hi i am trying to get this assignment done for school. i have to create random number with 1 to 3 and display a message. heres what i got so far but im stuck.
#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
int number;
srand(time(0));
int randomNum = rand() %3+1;
number=3;
cout <<"Enter a number between 1 and 3:";
cin >> number;
cout <<endl;
if(number == randomNum){
cout<<"You guessed the right number"<<endl;
}
elseswitch(number){
case 1:
cout<<"You entered 1"<<endl;
if(number == randomNum)
cout<<"You guessed the right number"<<endl;
cout<<"Sorry not the right number"<<endl;
break;
case 2:
cout<<"You entered 2"<<endl;
if(number == randomNum)
cout<<"You guessed the right number"<<endl;
cout<<"Sorry not the right number"<<endl;
break;
case 3:
cout<<"You entered 3"<<endl;
if(number == randomNum)
cout<<"You guessed the right number"<<endl;
cout<<"Sorry not the right number"<<endl;
break;
}
return 0;
}
#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
int number;
srand(time(0));
int randomNum = rand() % 3 + 1;
number = 3;
cout << "Enter a number between 1 and 3:";
cin >> number;
cout << endl;
if (number == randomNum)
{
cout << "You guessed the right number" << endl;
}
else
{
cout << "Sorry not the right number" << endl;
}
return 0;
}