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

need help with my program add random seeding to the program so computer picks a

ID: 3886166 • Letter: N

Question

need help with my program

add random seeding to the program so computer picks a different number everytime you play. change the while loop to a do-while loop....also program won't run properly

#include <stdio.h> //i/o functions
#include <stdlib.h> //random functions

int main()
{
int theNumber = 0; //creates new variable
int maxValue = 10; //set the upper limit
theNumber = rand()%maxValue + 1; //get a pseudo-random number
int userNumber = 0; //start values off at 0 for good programming

printf( "Hey! Guess my number! It is between 1 and %i. " , maxValue );
scanf( "%i" , userNumber ); //get # from user
//as long as user guessed wrong, do this stuff again

while( userNumber != theNumber ) // != means does not
{
printf( "Wrong! Please try again! " );
scanf( "%i" , userNumber ); //get # again
}

printf( "Congratulations! You win! " );

return 0;
}

Explanation / Answer

#include <stdio.h> //i/o functions

#include <stdlib.h> //random functions

int main()

{

int theNumber = 0; //creates new variable

int maxValue = 10; //set the upper limit

theNumber = rand()%maxValue + 1; //get a pseudo-random number

int userNumber = 0; //start values off at 0 for good programming

//as long as user guessed wrong, do this stuff again

do // != means does not

{

printf( "Hey! Guess my number! It is between 1 and %d. " , maxValue );

scanf( "%d" , &userNumber ); //get # from user

}while( userNumber != theNumber );

if(userNumber == theNumber )

{

printf( "Congratulations! You win! " );

}

return 0;

}