Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This has to be done in C++ language //******************************************

ID: 645313 • Letter: T

Question

 This has to be done in C++ language //************************************************************************************************** // FILE:        lab07.cpp // // DESCRIPTION: A simple number guessing game. The compter selects a  //                              secret number within a user specified range. The user //                              then has a specified number of attempts in which to  //                              correctly guess the secret number. the program provides //                              helpful feedback after each guess. // //              This lab project illustrates the following C++ concepts: //              1. Writing functions. Function calls. Pass parameters by-value. Return values. //              2. Writing loops. //              3. Writing if statements, if-else statements, and if-elseif-elseif... statements. // // AUTHORS:      ( 

Explanation / Answer

Program:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[])
{
int secret_number;
int guess=0;
int play=1;
const int LOW=-100;
const int HIGH=100;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
while (play==1)
{
printf("I have stored a random number between 0 and 100, try and see if you can guess the number: ");
secret_number=rand()%(HIGH-LOW+1)+LOW;
while(guess!=secret_number)
{
scanf("%d",&guess);
if(guess==secret_number)
{
printf(" Your Guess was correct! The number is %d ", secret_number);
}
else if(guess>secret_number)
{
printf(" Guess was too high, try again ");
}
else
{
printf("Guess was too low, try again ");
}
}
printf (" Would you like to play again? Yes=1 or No=2 ");
scanf ("%d", &play);
}
system("pause");
return;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote