You are tasked to make an (almost) useless contraption that tells the user when they have entered either the number 1 or 2 to console.
When the user enters 1 the message “you have entered the number 1” should print to console, and when the user enters 2 the message “you have entered the number 2” should print to console.
Hint: This can be solved by having two conditions in the while loop. You will also need an if statement within the loop.
#include<iostream>
using namespace std;
int main()
{
cout<<"Please, enter something with numbers 1 or 2 and others\n";
char c;
while(c=getchar())
{
if(c=='1')
cout<<"you have entered the number 1\n";
else if(c=='2')
cout<<"you have entered the number 2\n";
}
}
Comments
Leave a comment