Tl;dr: Why doesn't this work?
So I've begun working through the tutorials on the website to start learning to code as a hobby. For the second tutorial on If statements and booleon algebra I wrote a program which tests the user's adding and subtracting skills and congratulates them, or not, appropriately. I'm copying and pasting all the code here, which I haven't commented on because I'm assuming it is so basic you guys will be able to figure it out easily. The problem arises when I run it and get both the answers wrong (purposefully obviously), instead of saying what it should say "Damn you suck at maths", it says "I guess you're ok at maths". I'm not sure if this is a problem with the syntax of the first "else if" or the second. Not really a huge problem as the program doesn't bother me but I'd like to know if there is a key bit of syntax that I haven't understood.
Thanks in advance guys!Code:#include <iostream> using namespace std; int main() { int firstnumber; int secondnumber; int thirdnumber; int answer1; int fourthnumber; int fifthnumber; int sixthnumber; int answer2; cout << "This program will check if your adding and subtracting is correct" <<endl; cout << "Type your first number: "; cin >> firstnumber; cin.ignore(); cout << "Type your second number: "; cin >> secondnumber; cin.ignore(); cout << "Type what you think they add up to: "; cin >> thirdnumber; cin.ignore(); if (firstnumber+secondnumber==thirdnumber){ cout<< "That's the first one right, good job!" << endl; answer1=1; } else { cout<< "Oops got that one wrong :/" <<endl; answer1=0; } if (answer1) { cout << "Now we will check if your subtracting is as good as your adding" <<endl; } else { cout << "Maybe your subtracting is better than your adding!" <<endl; } cout << "Enter your first number: "; cin >> fourthnumber; cin.ignore(); cout << "Now enter the number you are subtracting from it: "; cin >> fifthnumber; cin.ignore(); cout << "Now enter what you think the answer is: "; cin >> sixthnumber; cin.ignore(); if (fourthnumber-fifthnumber==sixthnumber && answer1) { cout << "Well done! Correct again" <<endl; answer2=1; } else if (fourthnumber-fifthnumber==sixthnumber && !answer1){ cout << "At least your subtracting is better than your adding!" <<endl; answer2=1; } else if (!fourthnumber-fifthnumber==sixthnumber && answer1) { cout << "At least your adding is better than your subtracting" <<endl; answer2=0; } else if (!fourthnumber-fifthnumber==sixthnumber && !answer1) { cout << "Oops, wrong again" <<endl; answer2=0; } if (answer1 && answer2){ cout << "Yay! You are great at Maths"; } else if (answer1 || answer2) { cout << "I guess you're OK at Maths"; } else if (!answer1 && !answer2){ cout << "Damn you suck at Maths!"; } cin.get(); return 0; }