I need to create a program that uses NESTED FOR-LOOPS. What I need to do: Have u
ID: 3652469 • Letter: I
Question
I need to create a program that uses NESTED FOR-LOOPS.What I need to do: Have user guess at 7 random #'s between 1 and 20. Let them have 5 guesses per #.(should be up to 35 guesses total) And compute & sucess rate (using #guessedright/7*100) keeping track of how many #'s user gets right.
output should be something like:
Guess @ Magic #1 -> guess1
(let them know if its too high or too low, right or wrong.)
guess2
guess3
guess4
guess5
Guess @ Magic #2 -> guess1
guess2
guess3
guess4
guess5
ect.ect...
Your sucess rate was ---%
This is a program that we used for guessing @ one # btwn 1 and 20, allowing the user to have 5 attempts.
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
// This program ask user to guess a # btwn 1 and 20. It gives the
user 5 chances to guess the correct #
// It also lets them know if they need to guess higher or lower,
and on which attempt they guessed right.
int magic;
int guess;
magic=rand()%20+1;
for(int i=1;i<=5;i++)
{
cout<<" Enter your Guess of a number beteewn 1 and 20 (Attempt
#"<<i<<"):";
cin>>guess;
if(guess==magic)
{
cout<<" *** Wow, You got it RIGHT! *** The magic number is:
"<<magic<<" "<<endl;
cout<<" You guessed right on Attempt #"<<i<<" ";
break;
}
else {
cout<<" ...Sorry, you're WRONG "<<endl;
if(guess<magic)
cout<<" Your guess is too low "<<endl;
else cout<<" Your guess is too high "<<endl;
}
cout<<" You have "<<5-i<<" attempts remaining ";
}
system("pause");
return 0;
}
Thank you.
Explanation / Answer
//you pretty much got it working, just case your program with a for loop 0-6 #include #include using namespace std; int main () { // This program ask user to guess a # btwn 1 and 20. It gives the user 5 chances to guess the correct # // It also lets them know if they need to guess higher or lower, and on which attempt they guessed right. int magic; int guess; for(int j=0;jRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.