0

whats wrong with this code!

just started learning if statements and decided to test it. I made a simple 2 question quiz. but no matter what the answer is it always says correct. thanks in advance! #include <iostream> using namespace std; int main() { cout<<"Welcome to history pop quiz"<<"\n first question"<<"\n when did world war 1 happen?\n"; int q1,q2,a,b; cin>>q1; if (q1=1914){ cout<<"correct!"; a=1; } else{ cout<<"wrong!"; a=0; } cout<<"next question"<<"\n when did world war 2 happen? \n"; cin>>q2; if (q2=1939){ cout<<"correct! \n"; b=a+1; } else{ cout<<"wrong! \n"; b=a+0; } cout<<"you scored "<<b; }

26th Jun 2017, 1:51 PM
yusif jehad
yusif jehad - avatar
2 ответов
+ 5
if (q1 == 1914) if (q2 == 1939) = is assignment like i assign variable age as 13 so age = 13 but to compare u use == is age equal to 13?
26th Jun 2017, 1:52 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
0
thanks. don't know how i missed that!
26th Jun 2017, 2:14 PM
yusif jehad
yusif jehad - avatar