Using variables two times (Help)

Hello,

I have a problem, I am making a simple program to improve my c++. I have a problem, when using the variable two times, it does not get updated.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int points = 0;
string website_name;
string hi;

cout << "What is this website name: ;
cin >> website_name;

if(website_name == "cplusplus")
{
cout << "Good job, you have earned a point";
cout << "Current points: " << points + 1;
}

cout << "Please write the word 'hi' : ";
cin >> hi;

if(hi == "hi")
{
cout << "Good job, you have earned a point";
cout << "Current points: " << points + 1;
} 


Aight, The first one the points goes to 1, and when you go to the next if statement the "hi" it remains 1. I want the points to come 2, Obviously if you got the answers right.

Thanks for your help:)
When you cout points+1, the value of points variable does not get incremented. To do so, add the line points++; after line 11.
Use ++points.

You don't need to add it after the line. Just replace points + 1.
Last edited on
Thanks abhishekm71 & iHutch105, iHutch105 solution worked smoothly.
I already had tried points++ but I guess I didn't notice to put it behind haha :)!

Thanks a lot guys :)
Topic archived. No new replies allowed.