Can someone help me fix my points/score system in c++?
Emel1235JR (0)

code:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int score = 0;
int number;

cout << "This is a math game." << endl ;
cout << "You will get some tasks, every task is one point." << endl ;
cout << "But if you fail one you lose." << endl ;
cout << " " << endl ;

cout << "0 + 5 = " ;
cin >> number ;

if(number == 5){
cout << "Next" << endl ;
 score = score + number;

score++;
}else{
cout << "Fail" << endl ;
cout << "Your score is: " << score << endl ;
return 0;
}

cout << "5 + 13 = " ;

cin >> number ;

if(number == 18){
cout << "Next" << endl ;
 score = score + number;

score++;
}else{
cout << "Fail" << endl ;
cout << "Your score is: " << score << endl ;
return 0;
}

cout << "18 - 6 = " ;
cin >> number ;

if(number == 12){
cout << "Next" << endl ;
 score = score + number;

score++;
}else{
cout << "Fail" << endl ;
cout << "Your score is: " << score << endl ;
return 0;
}

}

You are viewing a single comment. View All
mat1 (2518)

You're doing

     score = score + number;
   score++;

Every time you get the answer right, so it increases your score by your input and by 1.
Try removing score = score + number; on lines 47, 34, and 21.
Also, next time you post a question, please leave a link to your repl and explain what the issue is.
Please mark this comment as the answer if it answered your question. Thanks!