View previous topic :: View next topic |
Author |
Message |
favoritio Expert Cheater Reputation: 0
Joined: 09 Sep 2006 Posts: 111 Location: USA 4 life the g cove state not saying
|
Posted: Wed Mar 14, 2007 5:05 pm Post subject: Only people dat know C++ come in? |
|
|
tell me how good my calculator code is from 1 - 10. Lol. Im trying to learn C++ so I can make $$$$ and hack ms so bad lol. And also I wanna learn how to add a square root function so I can find square roots of numbers. Thanks Code: |
#include <iostream>
using namespace std;
int main ()
{
//This is my calculator which will do every calculation in a second of two numbers only
int a; //Declaring my first whole number variable
int b; //Declaring my second whole number variable
int c; //Just a trick to distract while lol so dat my program may continue
double d; //Declaring my first decimal varible
double e; //Declaring my second decimal variable
int diff; //Allowing me to do subtraction with whole numbers
int sum; //Allowing me to do addition with whole numbers
int product; //Allowing me to do multiplication with whole numbers
int quotient; //Allowing me to do division with whole numbers
double diffd; //Allowing me to do subtraction with decimals
double sumd; //Allowing me to do addition with decimals
double productd; //Allowing me to do multiplication with decimals
double quotientd; //Allowing me to do division with decimals
double firstsquare; //Allowing me to have my first whole number squared;
double secondsquare; //Allowing me to have my second whole number squared
double firstsquared; //Allowing me to have my first decimal number squared;
double secondsquared; //Allowing me to have my second decimal number squared
cout<<" Always read this before continuing thanks for your time. Please type in the number 1 or a higher number and den press enter so dat you can use my calculator dat is the code to be able to use my calculator so if you dont do this you will not use my calculator. Oh yeah and dont forget to type in the number 1 or a higher number and then press enter to use my calculator lol.";
cin>>c;
while (c >= -1000000) {
cout<<"This calculator will do the calculation of two numbers in a second \n";
cout<<" If you want to use decimals type in da number 1 and then press enter \n";
cout<<"Please enter your first whole number ";
cin>>a;
if (a >= 2) {
cout<<" The number you just entered was " <<a<< "\n";
cout<<" Please enter your second whole number ";
cin>>b;
cout<<" The number you just entered was " <<b<< "\n";
sum = a + b;
product = a * b;
firstsquare = a * a;
secondsquare = b * b;
if (a > b) {
diff = a - b;
}
else {
diff = b - a;
}
if (a > b) {
quotient = a / b;
}
else {
quotient = b / a;
}
cout<<" The sum of your numbers is " <<sum<< "\n" " The diference of your numbers is " <<diff<< "\n" " The quotient of your numbers is " <<quotient<< "\n" " The product of your numbers is " <<product<< "\n";
cout<< a<< " squared is " <<firstsquare<< "\n";
cout<< b<< " squared is " <<secondsquare<< "\n";
}
else if (a <= 1) {
cout<<" Please enter your first decimal ";
cin>>d;
cout<<" The number you just entered is " <<d<< "\n";
cout<<" Please enter your second decimal number ";
cin>>e;
cout<<" The number you just entered is " <<e<< "\n";
productd = d * e;
sumd = d + e;
firstsquared = d * d;
secondsquared = e * e;
if (d > e) {
diffd = d - e;
}
else {
diffd = e - d;
}
if (d > e) {
quotientd = d / e;
}
else {
quotientd = e / e;
}
cout<<" The sum of your numbers is " <<sumd<< "\n" " The diference of your numbers is " <<diffd<< "\n" " The quotient of your numbers is " <<quotientd<< "\n" " The product of your numbers is " <<productd<< "\n";
cout<< d<< " squared is " <<firstsquared<< "\n";
cout<< e<< " squared is " <<secondsquared<< "\n";
}
}
} |
Last edited by favoritio on Thu Mar 15, 2007 6:59 pm; edited 1 time in total |
|
Back to top |
|
|
Aetherine Master Cheater Reputation: 0
Joined: 07 Mar 2007 Posts: 278 Location: The place you'd least expect me.
|
Posted: Wed Mar 14, 2007 5:10 pm Post subject: |
|
|
It's a little messy with the cout's. Don't be afraid to use multiple cout's to make it more organized.
Also, I believe there's a function for getting a square root.
http://www.cplusplus.com/reference/clibrary/cmath/sqrt.html
_________________
ᆲᅨᆰ예ᄈᆵᆬ○ᆭᆵ'ᅨ¦ᅮ¥ᅮ.ᅨ>=$
|
|
Back to top |
|
|
Devv Expert Cheater Reputation: 0
Joined: 21 Jan 2006 Posts: 173
|
Posted: Wed Mar 14, 2007 5:14 pm Post subject: |
|
|
Yayyyy! Someone learning C++. Well, the math lib has pretty much all the functions you need but I guess you want a challenge.
Try using strings to calculate from since int's are limited. Make your own functions and start at the bottom (add) and work your way up.
Add some cool ascii graphic picture of a calculator for startup. Add some help commands -h for help -a for about -s for syntax etc. I also suggest that you use argv, argc for input. (If you can use them)
[EDIT]Int main is a good start of every program!
_________________
|
|
Back to top |
|
|
favoritio Expert Cheater Reputation: 0
Joined: 09 Sep 2006 Posts: 111 Location: USA 4 life the g cove state not saying
|
Posted: Wed Mar 14, 2007 5:26 pm Post subject: |
|
|
I dont know how to make a graphic picture of a calculator or any of those graphic things. I only can write programs. Lol
|
|
Back to top |
|
|
Noz3001 I'm a spammer Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Wed Mar 14, 2007 5:33 pm Post subject: |
|
|
instead of:
Code: |
double 1;
double 2;
double 3;
|
try:
Faster and smaller.
|
|
Back to top |
|
|
favoritio Expert Cheater Reputation: 0
Joined: 09 Sep 2006 Posts: 111 Location: USA 4 life the g cove state not saying
|
Posted: Wed Mar 14, 2007 5:35 pm Post subject: |
|
|
noz3001 wrote: | instead of:
Code: |
double 1;
double 2;
double 3;
|
try:
Faster and smaller. |
oh yea that is lol didnt think about that thanks noz.
|
|
Back to top |
|
|
Noz3001 I'm a spammer Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Mar 15, 2007 8:28 am Post subject: |
|
|
Devv wrote: | Yayyyy! Someone learning C++. Well, the math lib has pretty much all the functions you need but I guess you want a challenge.
Try using strings to calculate from since int's are limited. Make your own functions and start at the bottom (add) and work your way up.
Add some cool ascii graphic picture of a calculator for startup. Add some help commands -h for help -a for about -s for syntax etc. I also suggest that you use argv, argc for input. (If you can use them)
[EDIT]Int main is a good start of every program! |
Ha, challenge? 2 * 2?
|
|
Back to top |
|
|
Flyte Peanuts!!!! Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Thu Mar 15, 2007 10:15 am Post subject: |
|
|
It looks really messy, but I suppose it will do what you need. Remember to stick a:
At the end of the function, since a non-void function should have a return at the end.
|
|
Back to top |
|
|
DeltaFlyer Grandmaster Cheater Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Thu Mar 15, 2007 7:50 pm Post subject: |
|
|
You know.... doubles can hold numbers larger than 1...
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
Back to top |
|
|
BlackKilla Expert Cheater Reputation: 0
Joined: 02 Jul 2006 Posts: 207 Location: North America ~Rollin up the Trees...
|
Posted: Fri Mar 16, 2007 3:03 pm Post subject: |
|
|
I would give it say an 7,But the thiang with square roots,Look at this to get a prospective on it
Code: |
The square root of a number is just the number which when multiplied by itself gives the first number. So 2 is the square root of 4 because 2 * 2 = 4.
Start with the number you want to find the square root of. Let's use 12. There are three steps:
1. Guess
2. Divide
3. Average.
... and then just keep repeating steps 2 and 3.
First, start by guessing a square root value. It helps if your guess is a good one but it will work even if it is a terrible guess. We will guess that 2 is the square root of 12.
In step two, we divide 12 by our guess of 2 and we get 6.
In step three, we average 6 and 2: (6+2)/2 = 4
Now we repeat step two with the new guess of 4. So 12/4 = 3
Now average 4 and 3: (4+3)/2 = 3.5
Repeat step two: 12/3.5 = 3.43
Average: (3.5 + 3.43)/2 = 3.465
We could keep going forever, getting a better and better approximation but let's stop here to see how we are doing.
3.465 * 3.465 = 12.006225
That is quite close to 12, so we are doing pretty well. |
It might help,When dealing with logical stuff like this, in programming it's better to know how we get an answer and then base a formula on what we got.
**EDIT**
After i reviewed the post a couple of times I guess this would work
Code: |
float x,y,w //X is the user number,and Y is the average,W is the outcome of x/y
int ee //ee is are variables in our for loop
do
{
w=x/y
for(ee;ee<=5000;ee++;)
(w+ee)/2=y
}while(y!=x)
|
_________________
|
|
Back to top |
|
|
Flyte Peanuts!!!! Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Mar 16, 2007 7:09 pm Post subject: |
|
|
Also, implement a check in your code so you don't divide by 0.
|
|
Back to top |
|
|
Death4ngel Grandmaster Cheater Supreme Reputation: 0
Joined: 23 Sep 2006 Posts: 1226 Location: Singapore
|
Posted: Fri Mar 16, 2007 8:34 pm Post subject: |
|
|
#include <cmath>
using namespace std;
void main() {
sqrt(4);
}
//I think. Can't remember the actual one.
_________________
//GOD!!! THOSE STUPID RETARDED SHITHEADS NEVER MAKE IT PAST THIS STEP!!!!!!
//Thats why it's out....
|
|
Back to top |
|
|
Noz3001 I'm a spammer Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sat Mar 17, 2007 5:47 am Post subject: |
|
|
Flyte wrote: | Also, implement a check in your code so you don't divide by 0. |
It's awsome when you do. The program crashes.
|
|
Back to top |
|
|
lukechin Grandmaster Cheater Reputation: 0
Joined: 24 Jun 2006 Posts: 536 Location: in willy wonkas factory
|
|
Back to top |
|
|
Aetherine Master Cheater Reputation: 0
Joined: 07 Mar 2007 Posts: 278 Location: The place you'd least expect me.
|
Posted: Thu Mar 29, 2007 7:57 pm Post subject: |
|
|
Death4ngel wrote: | #include <cmath>
using namespace std;
void main() {
sqrt(4);
}
//I think. Can't remember the actual one. |
void main()?!
NOOOOOOOOOOOOO!
_________________
ᆲᅨᆰ예ᄈᆵᆬ○ᆭᆵ'ᅨ¦ᅮ¥ᅮ.ᅨ>=$
|
|
Back to top |
|
|
|