Numbers of Interest using Input/Loops?

I just need help or at least a few pointers on how to get the computer to go through numbers 1-2000000000 and tell me which numbers contain the number seven. And if someone could also help me fix the major loop at the end because i keep getting an error message that my bool 'again' isn't being initialized.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  #include <iostream>
using namespace std;

int const MINIMUM_VALUE = 0;



int main(void)

{
	//// Prompt For Amount of Special Numbers ////
	while (true)
	{

		//// User Input ////

		while (true)
		{
			int howManyNumbers;
			cout << "How many really interesting numbers would you like to see? ";
			cin >> howManyNumbers;
			cin.ignore(999,'\n');

			if ( cin.fail() )
			{
				cin.clear ();
				cout << endl;
				cout << "Please enter an integer." << endl; 
				cout << endl;
				cin.ignore(999,'\n');
				continue;
			}
			else if ( howManyNumbers < 0)
			{
				cout << endl;
				cout << "Value out of range. Please enter a value within the range of " << endl;
				cout << "[ " << MINIMUM_VALUE << "..." << INT_MAX << " ]." << endl;
				cout << endl;
				continue;
			}
			else if ( howManyNumbers == 0 )
				return 0;

			break;

		}

		//// Process ////

		
		/// need to get the computer to recognize all of the interesting and very interesting numbers. so let's start with just numbers that have a seven seeing as seven is the number of interest.
		
		//// do while loop?

			
		//// Output ////

		cout << " The first really interesting number is " ;
		
		cin.ignore(999,'\n');

		int interestingNumber;
		cout << " It is the " << interestingNumber << "th interesting number." << endl;

		cin.ignore(999,'\n');

		//// Reinitiate Program? ////
		
		// 2 Finish
		

		bool again;
		while (true)
		{
			int againResponse;
			cout << endl;
			cout << "How many more interesting numbers would you like to see? ";
			cin >> againResponse;
			cin.ignore(999,'\n');

			if ( cin.fail () )
			{
				cin.ignore(999,'\n');
				cout << endl;
				cout << "Please enter an integer. " << endl;
				
			}
			else if ( againResponse < 0 )
			{
				cout << endl;
				cout << "Value out of range. Please enter a value within the range of " << endl;
				cout << "[ " << MINIMUM_VALUE << "..." << INT_MAX << " ]." << endl;
				continue;
			}
			else if ( againResponse == 0 )
			{
				again = false;
				break;
			}
			else
				again = true;
				break;
		}
		if ( !again ) break;
	}
	
}
For the "bool" problem. Look at each of the if statements, do all of them initialize again? Why not initialize this variable when you declare it?

Also look at that last else statement. How many lines do you think will be included with that statement? Hint: it's not two.

Also don't forget if the input stream fails you must clear() the error state before you can do anything with that stream.

Topic archived. No new replies allowed.