while user == gulible star 3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main()
{
    int count = 0;
    int number = 99;

    while (number != count)
    {
        cout << "Please Enter any number other than "<< count <<endl;
        cin >> number;

        if (count == number)
        break;

        else
        count++;

        //return 0;
    }
}


Hello again, been trying to refresh my console c++ memories after taking a class with visual c++ Anyway!

Here is an example of whats wrong:
Please enter a number other than 0 :
User: 0 // this will exit the program as intended!

however inputting a ONE will also exit the program as Unintended.. but nothing else. So i am extremely confused as to how my count can be more than one variable at a time!

Thanks in Advance

-Vlad
Do a desk test.
18
19
else
        count++; // ? 
Hello vlad61 , or salut if you are romanian.
Since the count variable will increase by 1 every time a check for equality with the input from the user is made, it will eventually reach the number that the user has typed and the loop will break, terminating the program.
If you type 1 , 0 will not be equal to 1 ,count will become 0+1=1, so if (1 == 1) break; will execute and that's that.
What did you want this program to do?
http://www.cplusplus.com/forum/articles/12974/

trying to do the second star here on "While( user == gullible )" (third assignment)

I THINK i understand what you are saying, Ill try this with a different approach

and what is a desk test ne555?

@pva why thank you I am half romanian!
Last edited on
Get paper and pencil and pretend that you are the computer. The idea is to follow the code and see how the variables change.
Yeah i see what it is now haha. If i enter a number that is one more above what the count is, then the next itteration calls false that the count == number! so yeah ill just have to write it differently thanks
I recommend to study the for , while and do while loops a bit more and understand exactly how they are used.
Take a look at this program.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream> // so you can use cout

int main() {

int input = 0; // variable to hold the number that the user types from the keyboard
// this loop will repeat until the input is 5
do {
  cout << "Enter a number:";   // inform the user to type a number
  cin >> input;     // save the value in the input variable
  if (input == 5) {  // check it input is 5
       cout << "You weren't suppose to type that number !!!";      // if it is , write this message
       break;}        // and exit the loop
while(input != 5); 

return 0;
} 

Topic archived. No new replies allowed.