Question

Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent generates a secret letter for the user to gueWhen the program starts, it must print the following: BUZZ, HUM, ZAP... Powering up the P1-AI-Bot... AI: Welcome to The BasWhen the user guesses correctly, the Al must respond as follows and prompt the user whether they want to play again, or not,The program must also validate the users input. When the user inputs a digit, the program must respond as follows: AI: TurnAn example of the completed program, with user input: BUZZ, HUM, ZAP... Powering up the P1-AI-Bot... AI: Welcome to... TheOne final requirement is that the simple Al must politely insult the player if they have taken more than 25 guesses at the se

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include<ctype.h>

int main()
{
char letters[]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int gameRounds=1;

printf("BUZZ,HUM,ZAP... Powering up the P1-AI-Bot...\n");
printf("\n");
printf(" \tAI:Welcone to \"The 'Basic' Letter Guellsing Game\"!\n");
bool gameloop=true;
while(gameloop){
int turn=1;
srand(time(0));
int comChoice=rand()%26;

printf("\tAI:Here we go ...");
for(int i=0;i<26;i++){
if(i==comChoice){
printf("%c",toupper(letters[i]));
}else{
printf("%c",letters[i]);
}
}
printf("...\n");
printf(" \tAI:I'm thinking of a secret letter,can you guess it...\n");
bool loopControl=true;
while(loopControl){
printf(" \tAI:Turn %d,What is your guess?\n",turn);
printf("\n");
printf("Human:");
char humanGuess;
humanGuess=getchar();
while ((getchar()) != '\n');
printf("\n");
//getting index of guess..
int indexOfGuess=-1;
for(int i=0;i<26;i++){
if(tolower(humanGuess)==letters[i]){
indexOfGuess=i;
break;
}
}

if(indexOfGuess!=-1 && indexOfGuess<comChoice){
char str[]="after";
turn++;
printf("\tAI:Wrong... my secret letter comes %s %c in the alphabet... \n",str,humanGuess);
if(turn>25){
printf("\tAI:This is Stupidity... there are total 26 letter in the alphabet!....\n");
}
}

if(indexOfGuess!=-1 && indexOfGuess==comChoice){
printf("\tAI:Well done!\n");
printf("\tAI:You took %d turns! Game over!\n",turn);
printf("\tAI: Play again (y/n)?\n");
printf("\n");
printf("Human:");
char play;
play=getchar();
while ((getchar()) != '\n');
printf("\n");
if(play=='y'||play=='Y'){
gameloop=true;
loopControl=false;
gameRounds++;
}
if(play=='n'||play=='N'){
gameloop=false;
loopControl=false;
}

}

if(indexOfGuess!=-1 && indexOfGuess>comChoice){
char str[]="before";
turn++;
printf("\tAI:Wrong... my secret letter comes %s %c in the alphabet... \n",str,humanGuess);
if(turn>25){
printf("\tAI:This is Stupidity... there are total 26 letter in the alphabet!....\n");
}
}

if(isdigit(humanGuess)){
printf("\tAI:Wrong... %c is a digit,that is not a letter!");
turn++;
}

if(!isalpha(humanGuess)&& !isdigit(humanGuess)){
printf("\tAI:Wrong... wow,%c is not a letter!\n",humanGuess);
turn++;
}
}
}
printf("\tAI: Thanks for playing %d rounds with me!\n",gameRounds);
printf("\tAI: G\n");
printf("\tAI: o\n");
printf("\tAI: o\n");
printf("\tAI: d\n");
printf("\tAI: b\n");
printf("\tAI: y\n");
printf("\tAI: e\n");
printf("\tAI: \n");
printf("\tAI: H\n");
printf("\tAI: u\n");
printf("\tAI: m\n");
printf("\tAI: a\n");
printf("\tAI: n\n");
printf("\tAI: !\n");
printf("\n");
printf("Powering down the P1-AI-BOT... FIZZ,POP,BANG!");
return 0;
}

//=============================ScreenShot====================================

Add a comment
Know the answer?
Add Answer to:
Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Develop a letter guessing game in this assignment using Java. Requirements: 1). When the game...

    JAVA Develop a letter guessing game in this assignment using Java. Requirements: 1). When the game is started, generate a random letter between A and Z; 2). Display a message "I have a secret letter (A to Z), can you guess what it is?"; 3). Read the user's answer; 4). Compare the user's answer and the random secret letter generated; 5). If the user answer is before the random secret letter in the alphabet, display "Incorrect. Try something bigger" and...

  • Write a program that allows a user to play a guessing game. Pick a random number...

    Write a program that allows a user to play a guessing game. Pick a random number in between 1 and 100, and then prompt the user for a guess. For their first guess, if it’s not correct, respond to the user that their guess was “hot.” For all subsequent guesses, respond that the user was “hot”if their new guess is strictly closer to the secret number than their old guess and respond with“cold”, otherwise. Continue getting guesses from the user...

  • Write a Java application program that plays a number guessing game with the user. In the...

    Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() :                    new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...

  • Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

    Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...

  • Please write a C# program that where a player will play a guessing game with the...

    Please write a C# program that where a player will play a guessing game with the range of 1-100. Each time the play guesses a number, and it is not correct the program should indicate if the number is more or less than what the player guessed. The play should be able to guess until the correct number has been guessed. If an invalid number is entered, such as: 1.24 (real number), or asd (string). The program should tell user...

  • c++ launguage please help The game Pico Fermi Bagel is a number guessing game. The computer...

    c++ launguage please help The game Pico Fermi Bagel is a number guessing game. The computer picks a secret number: the secret number must be 3 digits, none of the digits can be the same, and it cannot start with a zero. 104 is OK, but 091 and 212 are not. The user tries to guess the secret number - if none of the digits in the user's number are in the secret number, then the program replies with BAGEL...

  • (C++) Write a program to play the Card Guessing game. Your program must give the user...

    (C++) Write a program to play the Card Guessing game. Your program must give the user the following choices: a. Guess the face value of my card. b. Guess only the suit of the card. c. Guess both the face value and the suit of the card.. Before the start of the game, create a deck of cards. Before each guess, use the function random_shuffle to randomly shuffle the deck. Also include vector into the program. (C++)

  • Overview In this exercise you are going to recreate the classic game of hangman. Your program...

    Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...

  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

  • JAVA PROGRAM: Guessing Game Objective The student will write an individualized program that utilizes conditional flow...

    JAVA PROGRAM: Guessing Game Objective The student will write an individualized program that utilizes conditional flow of control structures in Java. Specifications For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT