#include <iostream>
usingnamespace 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!
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?
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;
}