Ask coding questions

← Back to all posts
1
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;
}

}

Answered by mat1 (2242) [earned 5 cycles]
View Answer
Commentshotnewtop
2
mat1 (2242)

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!

2
ryanhcode (84)

Can you tell us what is wrong and give us a link to the repl?

1
heyitsmarcus (285)

Can you please give some more details on what your problem is? Your C++ code runs fine. Although, you should put it into a repl beforehand, and then post the repl link instead of raw pasting the code.

You can look at the Markdown link below any comment to the right. Put three backticks (the default key for the ~ key) to start the code block, go to a new line, paste your code in, and then go to a new line, and put three more backticks.