so I want to write a program that if you didn't write the number 5 ten times you'll get praised other you'll get scolded.
I used int x as a counter for how many times he didn't write the number 5.
Note: after the if in the loop executed it goes out of the loop why!
#include <iostream>
#include <cstdio>
int main()
{
int x = 1;
int a ;
int b = 0;
std::cout << "Don't write the number 5: ";
std::cin >> a;
if (a != 5) {
for (int i = 0; i != 5; i = a) {
x++;
std::cout << "Write another number other then 5: ";
std::cin >> a;
if (x = 10) {
a = 5;
b = 5;
}
}
}
if (b = 5) {
std::cout << "You weren't supposed to write the number 5!";
for (int i = 0; i = 4;) {
std::cin >> a;
};
}
std::cout << "you are so patient :)";
for (int i = 0; i = 4;) {
std::cin >> a;
};
}
#include <iostream>
int main()
{
constint N = 10 ;
constint AVOID_THIS = 5 ;
std::cout << "enter " << N << " integers. do not enter the number " << AVOID_THIS << '\n' ;
bool bad_input = false ;
for( int i = 0 ; i < N ; ++i )
{
std::cout << "number? " ;
int number ;
std::cin >> number ;
if( number == AVOID_THIS ) bad_input = true ;
}
if(bad_input) std::cout << "You weren't supposed to write the number " << AVOID_THIS << "!\n" ;
else std::cout << "you are so patient :)\n" ;
}