בעיות ב-++C

בעיות ב-++C

1. תכנתתי משחק טריוויה שבו בוחרים שאלה מתוך 4 נושאים. הבעיה היא שיש לי קטע אחד שבוחרים באפשרות 4 (מתמטיקה) וזה נכנס לאפשרות 2 (הסטוריה של העולם). הקוד:
cout <<"Choose a subject:\n x2: 1.cars\n x1: 2.History of world\n x1: 3.Comuter Games\n x3: 4.Mathematics\n"; cin >> ans11; if (ans11==1) { cout <<"enter the Model of Pego\n1.303\n2.304\n3.Punto\n4.Almoshino\n"; cin >> ans12; if (ans12==2) { cout <<" Y O U K N O W C A R S W E L L \a\n"; x=x+x3+x3; } else { cout <<" V E R Y N O T \n"; x=x-x3; } } else if (ans11=2) { cout <<"who was the first President of U.S.A?\n1.Jorg W. Boosh\n2.Abraham Linkolen\n3.Bil Klinton\n4.Jorg Woshington\n"; cin >> ans13; if (ans13==4) { cout <<" Y O U K N O W H I S T O R Y W E L L \a\n"; x=x+x3; } else { cout <<" V E R Y N O T \n"; x=x-x3; } } else if (ans11==4) { cout <<"30 + (50 x 2) + 80 = \n1.200\n2.210\n3.220\n4.190\n"; cin >> ans14; if (ans14==2) { cout <<" Y O U K N O W M A T H E M A T I C S W E L L\a\n"; x=x+x3+x3+x3; } else { cout <<" L O S E R\n"; x=x-x3; } } else if (ans11==3) { cout <<"enter the Game Footbol\n1.NBA\n2.Sims\n3.Fifa\n4.red alert\n"; cin >> ans15; if (ans15==3) { cout <<" Y O U A R E G O O D ! ! !\a\n"; x=x+x3; } else { cout <<" V E R Y N O T \n"; x=x-x3; } } cout <<"your "<< x <<" scores\n\n";​
 

melatonin

New member
הבעייה

בתנאי שבודק האם המשתמש הקיש 2, ביצעת השמה ans11=2 במקום השוואה ans11==2 הפקודה מציבה את הערך 2 בתוך המשתנה ומחזירה true, שכן המספר שתיים שונה מאפס. מכיוון שהוחזר true, מבוצע הבלוק ששייך להסטוריה.
 
למעלה