Hello everyone, I was working on a coding tutorial based on a question.
Question:
1. User is asked to enter any number.
2. If user key in number '5', a message will appear say "5 is no included."
This is my program//it turns out well
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
for (int i=0;i<100;i++)
{
cout<<"Enter a number: "<<endl;
cin>>number;
cout<<endl;
if(number==5)
{
cout<<"Hey! You are not supposed to enter 5!"<<endl;
cout<<"Enter another number: "<<endl;
cin>>number;
cout<<endl;
}
}
If I put Else{enter another number}=====Whenever I enter 5, the message of "not suppose to enter 5" is gone. Like:
if(number==5)
{
cout<<"Hey! You are not supposed to enter 5!"<<endl;
/*cout<<"Enter another number: "<<endl;
cin>>number;*/
cout<<endl;
}
else
{
cout<<"Enter another number: "<<endl;
cin>>number;
#include <iostream>
usingnamespace std;
int main(){
int number = 0;
for (int i=0;i<100;i++){
cout<<"Enter a number: "<<endl;
cin>>number;
cout<<endl;
if(number==5){
cout<<"Hey! You are not supposed to enter 5!"<<endl;
cout<<"Enter another number: "<<endl;
cin>>number;
cout<<endl;
}else{
cout<<"Enter another number: "<<endl;
cin>>number;
}
}
}