Jump to content

  • Log In with Google      Sign In   
  • Create Account

Please help me with a problem, im newbie to c++!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 koolkoder   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 July 2001 - 08:16 AM

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:"<

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 11 July 2001 - 08:23 AM

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



#3 nickr_21045   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 July 2001 - 08:26 AM

main returns int, that
should be

int main(void) { return 0; }

#4 ktuluorion   Members   -  Reputation: 392

Like
Likes
Like

Posted 11 July 2001 - 08:32 AM

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 =.

#5 acraig   Members   -  Reputation: 471

Like
Likes
Like

Posted 11 July 2001 - 10:10 AM

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

#6 koolkoder   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 July 2001 - 10:22 AM

THANK YOU SO MUCH peoples, by the way, im using vc++ 5.0 and i didnt get a warning... anyway thank you!


#7 Midnight Coder   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 July 2001 - 07:33 AM

A warning for that would probably be annoying, since often assignment is your intent (like for error checking a variable right after it is assigned a value).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS