This is the code i wrote for a simple calculator. The problem is that the choices aren't going through...if you compile it, you'll see.
if you compile it, make sure to keep on trying numbers, because it goes through the different functions 1 at a time, the selection part is what isn't working, look:

if (com = 1) {
cout<<"List of commands:"<<endl;
cout<<"Type 1 to access the addition part of the calculator"<<endl;
cout<<"Type 2 to access subtraction part of the calculator"<<endl;
cout<<"Type 3 for multiplication part of the calculator"<<endl;
cout<<"Type 4 to access the division part of the calculator"<<endl;
cout<<"Type 5 to access the square root part of the calculator"<<endl;

int functio;
cout<<"Please enter the function you would like to use now."<<endl;
cin>>functio;

your problem is where you check for equality, you use a single = which is for assignment, to test for equality you must use ==

for example where you have

if (functio = 3)

you should have

if (functio == 3)

hope this helps

01-06-2002

RpiMatty

you should NOT have the line "int main();" at the end of your functions. That should not compile, and if it does compile, your program will recursevly call itself which is not a good thing

01-06-2002

Crossbow

Also, since your functions aren't returning any values, you can set their return type to "void". EX:

void subtraction()
{
...
return; //returns to the place where the function was called from
//you don't need this unless you want to return in the middle of a function, but it works at the end just the same
}

Also, you can set your "int"s to "float"s and the user will be able to use decimals. Or even better is a double, which is twice as big.

A little thing I learned by error was that if you enter 0 as your second division number (divisor), it will crash your program.

You don't need to include windows.h, but it includes math.h which you do need to include for sqrt().

01-07-2002

Unregistered

pointlessly picky

Have a look into switch statements, to get rid of all your ifs and it will make your code easier to read.

01-07-2002

Smoose777

THANKS a LOT!! it works now..the only thing is, how can i make the program go back to a certain spot in the code so that the program won't quit after the user multiplies a number the app won't quit. thanks. that is why i had the int main() because i had a wierd idea that it would go to the int main() part of the program over again :) guess it doesn't. any help is apreciated :)
thanks again

01-07-2002

salvelinus

In main, put your code in a while loop, and give a choice, six maybe, to quit the program. If the user enters six, voila, the program ends.
For readability, on your if statements, you don't need brackets if the code after the if statement is only one line.