Backwards program!

So, once again, my coding is rustier than I thought! I try to do all of it without tutorials, make the knowledge mine, blah blah. Anyways, this program is supposed to take the user's input until either they enter the number equal to the number of iterations of the loop being used or the count reaches ten.

However, the counter only goes up when I type in the number of the count. This is not right!! Help! As always, please just offer hints, not solutions. I like to learn for myself but I need a direction to search. Here's the code:

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
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    int n;
    
    
    for(int count = 0; count != n; count++)
    {
       do
       {
              cout << "Please enter a number other than " << count << ": ";
              cin >> n;
       } while (n != count);
       
       if(count == 10)
       {
           cout << "You are more patient than I! Program terminated!";
           break;
       }
    }
    
    cout << "You terminated the program!" << endl;
    
    
    system("PAUSE");
    return 0;
}


Thanks!
-Cob
I'm a huge Green Day fan, and one of my all time favorite songs is "Redundant" off of the album "Nimrod". Any idea where I'm going with this?

Look at what you want your for loop to do and look at what your do while loop does.
Last edited on
Also, I would suggest that you stay away from using System("pause") Because it's bad for your program.

Here a link to see why system pause is bad:
http://www.cplusplus.com/articles/j3wTURfi/
I try to do all of it without tutorials

This makes absolutely no sense. Why would you refuse to learn?

As for your code, in the first iteration of the loop you're comparing count to n without giving n a value, so right now it's stuck with some garbage. I would initialize n somehow just for the sake of good practice. As for your program, I don't understand what you're trying to do. I think you're trying to have them enter numbers from 1-10, but whats to stop me from entering 9132534 every time?
Anyways, this program is supposed to take the user's input until either they enter the number equal to the number of iterations of the loop being used or the count reaches ten.
This contradicts your code! If you want them to enter the number of iterations, then why are you telling them not too, and why in your code are you looping until they enter something different?
Danny: The assignment required each loop as previous knowledge. I naturally assumed that i had to use all them haha I see your point!

Nice fail on my part! Thanks for the tip!

Hirokachi: Thank you for this advice also! As I'm trying to develop my programming skills towards a specific end, this was a very useful article!
Last edited on
Topic archived. No new replies allowed.