Option One: Psychic Game (Basic) You\'re going to make create a Psychic Game. Es
ID: 3903407 • Letter: O
Question
Option One: Psychic Game (Basic) You're going to make create a Psychic Game. Essentially, the app randomly picks a letter, and the user has to guess which letter the app chose. Put the following text on your page: Guess what letter I'm thinking of Wins: (# of times the user has guessed the letter correctly) Losses: (# of times the user has failed to guess the letter correctly after exhausting all guesses) Guesses Left: (# of guesses left. This will update) Your Guesses So Far: (the specific letters that the user typed. Display these until the user either wins or loses.) When the player wins, increase the Wins counter and start the game over again (without refreshing the page). When the player loses, increase the Losses counter and restart the game without a page refresh (just like when the user wins).
Explanation / Answer
#include<iostream>
#include<string>
#include<stdlib.h>
#include<time.h>
using namespace std;
using namespace std;
int main(){
string inp;
int tg = 0;
int tw = 0;
int tl = 0;
string s = "abcdefghijklmnopqrstuvwxyz";
srand(time(NULL));
while(true){
char a = s[rand()%26];
cout << "Enter number of guesses:";
int g;
cin >> g;
for (int i = 0; i<g; i++){
cout << "Guesses Left:" << g-i << " " << "Enter your guess: ";
cin >> inp;
if (inp[0] == 'a'){
cout << "You win ";
tw++;
break;
}
if (g-i-1 == 0){
cout << "You lose ";
tl++;
break;
}
}
tg++;
cout << "Continue(y/n)?";
string ch;
cin >> ch;
if (ch[0] == 'n')
break;
}
cout << "Total Games:" << tg << endl;
cout << "Wins:" << tw << endl;
cout << "Losses:" << tl << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.