>>and it worked fine but for some reason now it doesnt do what the program tells it to do'
Yes, it does do exactly what you told it to do. But that may or may not be what you want it to do. :mrgreen:
major problem is that you are using the = operator instead of == operator in the if statements
if( taco == 1 )
/blabla
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
ok i was just fiddiling around macking this program to see what would happen and it worked fine but for some reason now it doesnt do what the program tells it to do
this is my code
int main()
{
int taco,pizza,chicken,hamburger,hotdog,;
cout<<"from 1 to 3 enter what taco is then press enter";
cin>>taco;
<em><strong>if(taco=1)</strong></em>{pizza=2;}
<em><strong>if(taco=2)</strong></em>{pizza=3;}
<strong> <em>if(taco=3)</em></strong>{pizza=4;} // 3rd stmt
cout<<"taco="<<taco<<"pizza="<<pizza<<"chicken="<<chicken<<"hamburger="<<hamburger<<"hotdog="<<hotdog;;
system ("pause");
}";
The lines which i have underlined in your code are the statements which are causing problem to you. What you wanted to do was some condition checking but ended up assigning new values to the variable "taco" and overwriting the ones inputted by the user.
Hence your third stmt if (taco = 3) .... ends up assigning the value of 3 to taco and not checking whether the taco variable is 3 or not. That stmt alogn with the stmst i have highlighted should use the == operator instead of using the assignment operator which is = .
SO just put if (taco == 3) and like wise in your code and it should work fine.
Also using the system ("pause") to make the prog wait is considered bad programming practice since it invokes the OS specific routine "pause". Use getchar () instead, it achieves the same purpose.
Hope it helped, bye.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
the only thing i can think of is that there might be something wrong with the compiler.
from my code then pleas look over my code and tell me what the problem might be
Blaming the compiler is no way of solving the problem and the solution to your problem i have already stated in my previous post. Look there.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
> int taco,pizza,chicken,hamburger,hotdog,;
Does this even compile?
That trailing , looks like a syntax error to me.
> the only thing i can think of is that there might be something wrong with the compiler.
Er, no - it's all your code.
The chance of a newbie stumbling on a compiler bug is close enough to zero as to make no difference.
If you've got past "hello world", then you can be pretty sure the compiler is installed and working correctly.
You might want to add these options to your compiler (since you seem to be using dev-c++)
-W -Wall -ansi -pedantic -O2 -Werror
Those will trap a lot of programming mistakes before you get to run the code and observe "weird" behaviour.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
~s.o.s~ would it be more correct if i made all of my = into ==
Simply put it this way, when u want to compare some values you use the comparision operator which is == .
When you want to assign a value to a variable you need to use the assignment operator which is = .
Simple as abc.
So wat u want to do in ur current case ? U want to compare the values inputted by the user isnt it ? SO use the comparision operator. That will set you right and make your program work.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734