Please help me with a problem, im newbie to c++!
Im currently making the switch from vb to c++, and made a simple calculator to help me learn, however i am having a problem. first things first though, heres the code(the margins kinda screwed it up tho,):
#include
void main()
{
float numberone;
float numbertwo;
float answer;
char text;
cout<<"Type in a to add, m to multiply, or s to subtract:"<>text;
if (text = ''m'')
{
cout<<"Enter in the first number to multiply:"<>numberone;
cout<<"Enter in the second number to multipy:"<>numbertwo;
answer=numberone*numbertwo;
cout<<"The answer is:"<>numberone;
cout<<"Enter in the second number:"<>numbertwo;
answer=numberone-numbertwo;
cout<<"The answer is:"<>numberone;
cout<<"Enter in the second number:"<>numbertwo;
answer=numberone+numbertwo;
cout<<"The answer is:"<<answer<<endl;
}
}
______________________________________________________________
first of all, ferget waht i said about the margins, any way, when i run it and enter in a for example, i instead get all the i/o to multiply, basically, whichever if statement is at the top, it always uses that one..
any help would be appreciated, sorry for posting a basic question tho.. PLEASE HELP!
{}_{} -[_]- /
July 11, 2001 02:23 PM
OK you just made a simple error.
Change all of your if statements to
if (text== ''m'') {
}
etc.
There are two equal signs in a comparison in c++.
Mike
Change all of your if statements to
if (text== ''m'') {
}
etc.
There are two equal signs in a comparison in c++.
Mike
yes, that won''t give an error though. I used to void main as well when i first started with c++.
The only thing i can see that would cause that is the single =.
The only thing i can see that would cause that is the single =.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]
quote:
The only thing i can see that would cause that is the single =.
Depending on your compilier this should generate a warning along the lines of "Possible incorrect assigment". This should be a good lesson on making sure you check those warnings.
Andrew
THANK YOU SO MUCH peoples, by the way, im using vc++ 5.0 and i didnt get a warning... anyway thank you!
{}_{} -[_]- /
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement