Write a number guessing game in which the computer selects a

Write a number guessing game in which the computer selects a random number in the range of 0 to 100. and users gel a maximum of 20 attempts to guess it. At the end of each game, users should be told whether they won or lost, and then be asked whether they want to play again. When the user quite, me program should output the total number of wins and losses. to make the game more interesting, the program should vary the working of the messages that it outputs for winning, for losing, and for asking for another game. Use Do-While and switch statements where possible. Write a C++ program that reads a time in numeric form and prints it out in English. The time is input as hours and minutes, separated by a space. Hours are specified in 24-hour military time (e.g. 15 is 3pm), but the output should be in 12-hour AM/PM format Note that noon and midnight are special cases. Here are some examples:

Solution

1. As the question didnot mention of any language , lets use python for simplification, later using this code you can convert it to any language , on java / c++/ c , no probelm . Just understand the logic !

now the problem statement is very simple , we have to build a number guessing game where a user gets only 20 chance , so we need to basically take a varible named \"attempt\" in while loop which will be iterating 20 times .

#built in function for python that will generate random number

import random

attempts = 0

print(\'Hello! What is your name?\')
myName = input()

number = random.randint(1, 100)
print(\'Well, \' + myName + \', I am thinking of a number between 1 and 100.\')

while attempts < 20:
print(\'Take a guess.\')
guess = input()
guess = int(guess)
attempts = attempts + 1

if guess < number:
print(\'Your guess is too low.\')

if guess > number:
print(\'Your guess is too high.\')

   if guess == number:
break

if guess == number:
attempts = str(attempts)
print(\'Good job, \' + myName + \'! You guessed my number in \' + attempts + \' guesses!\')

if guess != number:
number = str(number)
print(\'Nope. The number I was thinking of was \' + number)

Let me know if you need any help converting it to C++ / java !

2) Below code written in so simple way , looking at it , you will understand

#include<iostream>
#include <string>

   using namespace std;
int timeNow(int, int);
void gettimeNow(int HOUR, int MINUTE);

int main()
{     

   int MINUTE;
   int HOUR;
     
   cout << \"\ enter a time in the 24 hour clock format: \ \" << endl;
  
   cin >> HOUR >> MINUTE;
     
   HOUR = timeNow(HOUR, MINUTE);
   gettimeNow(HOUR, MINUTE);

   return 0;
}
int timeNow(int HOUR, int MINUTE)//use only HOUR and MINUTE within the timeNow function
{  
   switch (HOUR)// swtich statement for the HOUR
   {
      
   case 1 :
   case 13: cout << \"One\";
                   break;
   case 2 :
   case 14: cout << \"Two\";
   break;
   case 3 :
   case 15: cout << \"Three\";
   break;
   case 4 :
   case 16: cout << \"Four\";
   break;
   case 5 :
   case 17: cout << \"Five\";
   break;
   case 6 :
   case 18: cout << \"Six\";
   break;
   case 7 :
   case 19: cout << \"Seven\";
   break;
   case 8 :
   case 20: cout << \"Eight\";
   break;
   case 9 :
   case 21: cout << \"Nine\";
   break;
   case 10:
   case 22: cout << \"Ten\";
   break;
   case 11:
   case 23: cout << \"Eleven\";
   break;
   case 12: cout << \"Twelve\";
   }
   if (MINUTE >= 20) // a switch statement within this if statement for use with the MINUTE variable
   {
       switch(MINUTE)
       {
           case 20: cout << \" twenty\";
                   break;
           case 21: cout << \" twenty one\";
                   break;
           case 22: cout << \" twenty two\";
                   break;
           case 23: cout << \" twenty three\";
                   break;
           case 24: cout << \" twenty four\";
                   break;
           case 25: cout << \" twenty five\";
   break;
           case 26: cout << \" twenty six\";
                   break;
           case 27: cout << \" twenty seven\";
   break;
           case 28: cout << \" twenty eight\";
                   break;
           case 29: cout << \" twenty nine\";
   break;
           case 30: cout << \" thirty\";
                   break;
           case 31: cout << \" thirty one\";
                   break;
           case 32: cout << \" thirty two\";
   break;
           case 33: cout << \" thirty three\";
                   break;
           case 34: cout << \" thirty four\";
   break;
           case 35: cout << \" thirty five\";
                   break;
           case 36: cout << \" thirty six\";
   break;
           case 37: cout << \" thirty seven\";
                   break;
           case 38: cout << \" thirty eight\";
   break;
           case 39: cout << \" thirty nine\";
                   break;
           case 40: cout << \" forty\";
                   break;
           case 41: cout << \" forty one\";
   break;
           case 42: cout << \" forty two\";
   break;
           case 43: cout << \" forty three\";
   break;
           case 44:cout << \" forty four\";
   break;
           case 45: cout << \" forty five\";
   break;
           case 46: cout << \" forty six\";
                   break;
           case 47: cout << \" forty seven\";
   break;
           case 48: cout << \" forty eight\";
   break;
           case 49: cout << \" forty nine\";
                   break;
           case 50: cout << \" fifty\";
                   break;
           case 51: cout << \" fifty one\";
   break;
           case 52: cout << \" fifty two\";
   break;
           case 53: cout << \" fifty three\";
   break;
           case 54: cout << \" fifty four\";
   break;
           case 55: cout << \" fifty five\";
   break;
           case 56: cout << \" fifty six\";
   break;
           case 57: cout << \" fifty seven\";
   break;
           case 58: cout << \" fifty eight\";
   break;
           case 59: cout << \" fifty nine\";
   break;
       }
   }// Statement for MINUTE >= 20


   if (MINUTE < 20) // a switch statement within this if statement for use with the MINUTE variable
   {
       switch(MINUTE)
       {
           case 1: cout << \" one\";
   break;
           case 2: cout << \" two\";
   break;
           case 3: cout << \" three\";
   break;
           case 4: cout << \" four\";
   break;
           case 5: cout << \" five\";
   break;
           case 6: cout << \" six\";
   break;
           case 7: cout << \" seven\";
   break;
           case 8: cout << \" eight\";
   break;
           case 9: cout << \" nine\";
   break;
           case 10: cout << \" ten\";
                   break;
           case 11: cout << \" eleven\";
   break;
       case 12: cout << \" twelve\";
   break;
       case 13: cout << \" thirteen\";
   break;
           case 14: cout << \" fourteen\";
   break;
           case 15: cout << \" fifthteen\";
   break;
           case 16: cout << \" sixteen\";
   break;
           case 17: cout << \" seventeen\";
   break;
           case 18: cout << \" eighteen\";
   break;
           case 19: cout << \" nineteen\";
                   break;
       }
   }// Statement for MINUTE < 20
  
   if (MINUTE == 00)   //check that the MINUTE == 00, if so, print either Noon or Midnight
       {
           if(HOUR == 12)
               cout << \"Noon\";
           if (HOUR == 24 || HOUR == 00)
               cout << \"Midnight\";
       }//IF Statement for if MINUTE == 00
  
   if (HOUR < 12)
       cout << \" AM\" <<endl;
   else
       cout << \" PM\" <<endl;
  
   return HOUR;
}//timeNow function


void gettimeNow(int HOUR, int MINUTE)
{
   //if (HOUR < 12)
   cout << \"\ \" << HOUR << MINUTE <<endl;
   //else
       //cout << \"\ \" << HOUR << MINUTE << \" PM\" <<endl;

   system(\"pause\");
   return;
}//gettimeNow Function

 Write a number guessing game in which the computer selects a random number in the range of 0 to 100. and users gel a maximum of 20 attempts to guess it. At the
 Write a number guessing game in which the computer selects a random number in the range of 0 to 100. and users gel a maximum of 20 attempts to guess it. At the
 Write a number guessing game in which the computer selects a random number in the range of 0 to 100. and users gel a maximum of 20 attempts to guess it. At the
 Write a number guessing game in which the computer selects a random number in the range of 0 to 100. and users gel a maximum of 20 attempts to guess it. At the
 Write a number guessing game in which the computer selects a random number in the range of 0 to 100. and users gel a maximum of 20 attempts to guess it. At the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site