C++ or C Make sure no errors 59. This program is a simple guessing game. The com
ID: 3672218 • Letter: C
Question
C++ or C Make sure no errors 59. This program is a simple guessing game. The computer is to generate a random number between 1 and 20. The user is given up to five tries to guess the exact number. After each guess, you are to tell the user if the guessed number is greater than, less than, or equal to the random num- t is equal, no more guesses should be made. If the user hasnt guessed the number after five tries, display the number with a message that the user should know it by now and terminate the game A possible successful dialog I am thinking of a number between 1 and 20. Can you guess what it is? Your quess is low. Try again: 15 Your guess is low. Try againi17 Your guess is high. Try again: 16 10 Congratulations! You did it. A possible unsuccessful dialog I am thinking of a number betveen 1 and 20. Can you gquess what it is? 10 Your guess is low. Try again: 20 Your guess is high. Try again: 10 Your guess is low. Try again: 18 Your guess is high. Try again: 12 Sorry. The number was 15. You should have gotten it by now. Better luck next time. Your design for this program should include a separate function a one t get the user's guess, a function to print the unsuccessful message, ope s rint the successful message, and one to print the sorry messageExplanation / Answer
Please find the required codes below :
59)
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
int guess,i=0;
int num = rand()%(20-1 + 1) + 1;
cout << "I'm thinking of a number between 1 and 20. Can u guess what it is ?"<<endl;;
cin >> guess;
cout << num;
while(num!=guess && ++i<5){
if(guess<num){
cout << "Your guess is low. Try again:"<<endl;
}else{
cout << "Your guess is high. Try again:"<<endl;
}
cin >> guess;
}
if(num==guess){
cout << "Congratulations! You did it."<<endl;
}else{
cout << "Sorry. The number was " << num << "." << endl;
cout << "Better luck next time" << endl;
}
}
-------------------------------------------------------------------------------------------------------------------------
55)
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a,i=0;
cout << "Enter the angle:"<<endl;;
cin >> a;
if(a==0)
cout << "Lies on positive X-axis" << endl;
else if(a==90)
cout << "Lies on positive Y-axis" << endl;
else if(a==180)
cout << "Lies on negative X-axis" << endl;
else if(a==270)
cout << "Lies on negative Y-axis" << endl;
if(a>0 && a <90)
cout << "Lies on first quadrent" << endl;
if(a>90 && a <180)
cout << "Lies on second quadrent" << endl;
if(a>180 && a <270)
cout << "Lies on third quadrent" << endl;
if(a>270 && a <360)
cout << "Lies on fourth quadrent" << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.