Easy questions - nested looping and default??
Posted on 1998-07-18
The following code is already done for my homework and needs nothing more to meet the requirements. However, I want to do a couple of more things with it to make it look better. If anyone can direct me inthis, I'd really be grateful.
First, what this program does is take a digit entry and output whether the digit was 1, 4, or 9 and 3, 5, or 6 (seperate counts). If the entry (digits from 0 to 9, by the way) was neither of the six cases, then the counter ignores it and gives the current count and the number of digits processed so far. In this program, 20 digits are to be processed. So far, only the initial statement to start the user off is output. After the first number is entered, then only a blank space comes up for the next entry. SO, I'd like to add the word "AGAIN: " and have it loop each time a new digit is processed until the final one is counted (number 20, in this case). Maybe it's th elate hours I'm keeping these days, but I just can;t get it to work. Can someone help me with this?
Second, I want to add a default statement to the switch in the for of a message box error message. Now, I want the error message to come up any time anything other than 0 - 9 is pressed (less than 0 or greater than 9). When OK is pressed, the program picks up where the error occured and keeps going. (Example, on the 13th value entered, the user input 34. The program should display the error message box without starting over or ending the program. once OK is pressed, the program picks up at the 13th entry again). Currently, when I try this, the final WHILE statement near the end of the program executes (see below). Now, when YES is pressed in that instance, the program DOES pick up, while NO ends the program. How do I get a default MessageBox to display in the other's place - a proper display??
Here's the code. It's workable as-is. As I stated earlier inthis post, this IS homework. but, what I'm asking is for my own benefit, not for the instructors. What you see below is eough for them. Thanks in advance for all your assistance in this matter.
int ProcessedValues = 0;
int Count356 = 0;
int Count149 = 0;
cout << "Enter a number: " << flush;
while ((ProcessedValues < 20) && (cin >> Number) && (Number >= 0)
&& (Number <= 9))
cout << "Number of digits which were 3, 5, or 6: " << Count356
cout << "Number of digits which were 1, 4, or 9: " << Count149
cout << "Processed Values: " << ProcessedValues << endl;
while (MessageBox(NULL, "Would you like to process 20 more numbers?", "Again?",
MB_YESNO | MB_ICONQUESTION)==IDYES);
PS - I'm using Borland's Turbo C++ 4.5 for Windows compiler for this project.