Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 5 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 13 Jul 2017 My Price 14.00

guess the exact number

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 users if the guessed number is greater than, less than, or equal to the random number. If it is equal, no more guesses should be made. If the user hasn't guessed the number after five tries, display the number with a message that the user should know it by now and terminate the game.
Your design for this program should include a separate function to get the user's guess, a function to print the unsuccessful message, one to print the successful message, and one to print the sorry message.

No while. Only using if else statemet.

A Possible successful dialog:
I am thinking of a number between 1 and 20.
Can you guess what it is? 10
your guess is low. Try again: 15
Your guess is low. Try again: 17
Your guess is high. Try again: 16
Congratulations! You did it.

A possible unsuccessful dialog:
I am thinking of a number between 1 and 20.
Can you guess 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.

This program needs to be written in C.

This is what I have so far but i cant get it to compile. It gives me all kinds of read errors.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int getnumber();
void unsuccessful(int);
void successful();
void sorry(int);
int main()
{int randomnumber,number=-1,count=5;
srand(time(0));
randomnumber=(rand()%20)+1;
printf("I am thinking of a number between 1 and 20.\nCan you guess what it is? ");
while(randomnumber !=number)
     {
      number=getnumber();
        if(number==randomnumber)
            {successful();
            getch();
            return 0;
            }
        else
           if(count==1)
              {
              sorry(randomnumber);
              getch();
              return 0;
              }
           if(number<randomnumber)
          unsuccessful(1);
       else
          unsuccessful(0);
      count--;  
    }


}
void sorry(int n)
{
printf("Sorry. The number was %d.\nYou should have gotten it by now.\n",n);
printf("Better luck next time.");
}
int getnumber()
{int number;
scanf("%d",&number);
return number;
}
void unsuccessful(int n)
{if(n==1)
      printf("Your guess is low. Try again: ");
else
     printf("Your guess is high. Try again: ");
}
void successful()
{printf("Congratulations! You did it.\n");

Answers

(5)
Status NEW Posted 13 Jul 2017 05:07 PM My Price 14.00

Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- Th-----------ank----------- Yo-----------u f-----------or -----------usi-----------ng -----------our----------- we-----------bsi-----------te -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill-----------

Not Rated(0)