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

"#include <iostream>
using namespace std;
int main()
{
int taco,pizza,chicken,hamburger,hotdog,;
taco=0;
cout<<"from 1 to 3 enter what taco is then press enter";
cin>>taco;
if(taco=1){pizza=2;}
if(taco=2){pizza=3;}
if(taco=3){pizza=4;}
if(pizza=2){chicken=3;}
if(pizza=3){chicken=4;}
if(pizza=4){chicken=5;}
if(chicken=3){hamburger=4;}
if(chicken=4){hamburger=5;}
if(chicken=5){hamburger=6;}
if(hamburger=4){hotdog=5;}
if(hamburger=5){hotdog=6;}
if(hamburger=6){hotdog=7;}
cout<<"taco="<<taco<<"pizza="<<pizza<<"chicken="<<chicken<<"hamburger="<<hamburger<<"hotdog="<<hotdog;;
system ("pause");
}";

for some reason no mater what number i use (when runing it) it always puts the answer
taco=3pizza=4chicken=5hamburger=6hotdog=7press any key to continue . . .

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

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;

[I][B]if(taco=1)[/B][/I]{pizza=2;}
[I][B]if(taco=2)[/B][/I]{pizza=3;}
[B] [I]if(taco=3)[/I][/B]{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.

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

actually let me rephrase. when i first creaded the program it did what i wanted it to do but now the last time i ran it, with the same code, no matter what i input it always comes out the same. the only thing i can think of is that there might be something wrong with the compiler.

also
if there's a reason why this is happening

for some reason no mater what number i use (when runing it) it always puts the answer
taco=3pizza=4chicken=5hamburger=6hotdog=7press any key to continue . . .

from my code then pleas look over my code and tell me what the problem might be

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.

nevermind the dude above answerd my qustion

~s.o.s~ would it be more correct if i made all of my = into ==

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.