Counting Problem

Write your question here.
Hello All.
I'm new here and also new to C, C++. I use Dev-C++.
I want to learn to learn C++ for my basic needs.
First of all i have search whole google for this problem for about 1 week and still can't find any solution.
So i come to this problem. I want to create console that ask me to input a number, and if number is correct in "if statement", need to be counted starting from 1,2,3..., and if number is incorrect in "if statement", need to be counted from 1 again.
I can do that by put 2 counters start from 0. But what i'm asking for is when i hit a correct number after incorrect number in "else statement" i want the counter to be reset to 0 and start again counting like 1,2,3...
Problem in this code is that the counter won't reset and just keep adding counts.

What if done:
Please Enter The Number. 1
Hit Times 1
Please Enter The Number. 1
Hit Times 2
Please Enter The Number. 1
Hit Times 3
Please Enter The Number. 4
Miss Times 4
Please Enter The Number. 4
Miss Times 5
Please Enter The Number. 4
Miss Times 6
Please Enter The Number. 1
Hit Times 7
Please Enter The Number. 1
Hit Times 8
Please Enter The Number. 1
Hit Times 9

What i need:
Please Enter The Number. 1
Hit Times 1
Please Enter The Number. 1
Hit Times 2
Please Enter The Number. 1
Hit Times 3
Please Enter The Number. 4
Miss Times 1
Please Enter The Number. 4
Miss Times 2
Please Enter The Number. 4
Miss Times 3
Please Enter The Number. 1
Hit Times 1
Please Enter The Number. 1
Hit Times 2
Please Enter The Number. 1
Hit Times 3
and so on...

Please help me, and thank you all for rewiew

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  Put the code you need help with here.
 #include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

int count = 1;

int main(int argc, char** argv) 
{
	for(;;)
	{
		int a;
		cout << "Please Enter The Number.  ";
		cin >> a;
		if(a == 1 || a == 2 || a == 3)
			{
				cout << "Hit Times  " << count++ << endl;	
			}
		else
			{
				cout << "Miss Times  " << count++ << endl;
			}
	}
	return 0;
}
@TryHardGon

Is this what you're needing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>

using namespace std;



int main(int argc, char** argv) 
{
	bool miss = false;
	int count = 0;
	for(;;)
	{
		int a;
		cout << "Please Enter The Number.  ";
		cin >> a;
		if(a == 1 || a == 2 || a == 3)
			{
				if(miss == false)
				{
					count=1;
					miss = true;
				}
				else
				{
					count++;
				}
				cout << "Hit Times  " << count << endl;
			}
		else
			{
				if(miss == true)
				{
					miss = false;
					count = 1;
				}
				else
					count ++;
				cout << "Miss Times  " << count << endl;
			}
	}
	return 0;
}
@whitenite1
YES! It works that is what i need. THANK YOU VERY VERY MUCH!!! I own u a beer.
Last edited on
@TryHardGon

Thanks for the beer offer, but I don't really care for beer. But, I'll take a diet Pepsi, thank you.
Topic archived. No new replies allowed.