inserting comma and space
Nov 12, 2018 at 9:01pm UTC
I'm trying to correct the output in function enterNameToGuess. it asks user "what is guess number 1?" .."number 2 " ect. in a previous code I used a while loop to insert a "' " after each statment. IF the user types in an input with more then 1 word the compiler moves on to the next prompt.
[OUTPUT]what is you first guess? dr teeth.
[output]what is guess # 2? //one for "Dr"
[output] what is guess #3?// one for Teeth"
Most names on the list are multiple words.
namesUsed.txt
[
Bert
Ernie
Big Bird
Cookie Monster
Grover
Stater
Waldorf
Fozzie
Swedish Chef
Dr. Bunsen Honeydew
Beaker
Animal
Gonzo
Rowlf The Dog
Rizzo The Rat
Miss Piggy
Floyd Pepper
Dr.Teeth
Sweetums
Janice
Pepe The King Prawn
Camilla The Chicken
Mahna Mahna
Bobo The Bear
Lew Zealand
]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
using namespace std;
void gameWelcome();
//startNewGame();
string enterNameToGuess();
bool compareNameToFileAttempt();
bool determineScore();
void startGuessing();
//int displayMainMenu();
//int viewAttemptsInFile(string);
//viewAllTotalWins();
// displayNameattempt();
int main()
{
string guess, nameGuess; bool notValidGuess=true ;
gameWelcome();
startGuessing();
enterNameToGuess();
while (notValidGuess==true )
{
nameGuess = enterNameToGuess();
notValidGuess=compareNameToFileAttempt();
cout << "starting /" <<"enterNameToGuess" <<" /" <<endl;}
int detrmineScore;
// startNewGame();
//int displayMainMenu();
// displayQuitPlaying();
// viewAllTotalWins();
// compareNameToFile();
// displayNameattempt();
return 0;
}
void gameWelcome()
{char option='y' ;
cout<< left <<"It's time to play the music...\n\nIt's time to light the lights....\n\nIt's time to guess the Muppets on \"The Muppet Show\" tonight.\n\n" << left <<"Welcome to the Muppet guessing game." <<endl;
cout <<left<<"In this game you will have 10 tries to guess one of ten different muppets." <<left<<"\n\nWould you like to play a round?[y\\n]" << endl;
cin>>option;
//get(cin,option);
if (option=='n' || option == 'N' )
{
cout <<left<<
"____ _ _ ___ ____ ____ _ _ ____" <<"\n" <<left<<
"|___ |\\ | | \\ | __ |__| |\\/| |___" <<"\n" <<left<<
"|___ | \\| |__/ |__] | | | | |___" <<"\n" <<endl;
}
else if (option=='y' ||option == 'Y' )
{
cout<<"continue to main()" <<endl;
}
}
void startGuessing()
{
//bool notValidGuess=true;
cout<<"" <<"To start guesing." <<endl;
cout<<"Press a key and ENTER when ready." <<endl;
}
void enterNameTGuess()
{
//bool notValidGuess=true;
cout<<"To start guesing." <<endl;
cout<<"Press a key and ENTER when ready." <<endl;
}
string enterNameToGuess()
{
string name;
for (int i=0;i<11;i++)
{cout << "what is guess # " <<i+1<<"?" <<endl;
// if (i==1)
// {
// cout<< "What is your 1st guess?";
// }
// else if (i==2)
// {
// cout<<"What is your 2nd guess?";
// }
// else if (i==3)
// {
// cout<<"What is your 3rd guess?";
// }
// else if (i==4)
// {
// cout<<"What is your 4th guess?";
// }
// else if (i==5)
// {
// cout<<"What is your 5th guess?";
// }
// else if (i==6)
// {
// cout<<"What is your 6th guess?";
// }
// else if (i==7)
// {
// cout<<"What is your 7th guess?";
// }
// else if (i==8)
// {
// cout<<"What is your 8th guess?";
// }
// else if (i==9)
// {
// cout<<"What is your 9th guess?";
// }
// else if (i==10)
// {
// cout<<"What is your 10th guess?";
// }
cin >> name;
}
cout << "back to Main" <<endl;
return name;
}
bool compareNameToFileAttempt()
{ int score; string name; string nameGuess;
ifstream inFile;
ofstream outFile;
inFile.open("namesUsed.txt" );
while (inFile>>name)//new loop input the teamname....
{
if (name==nameGuess)//...if the team name equals the users guess....
{ //....increment score and close file mlb teams.txt
cout <<"Not correct" << endl;
return true ;
}
inFile.close();
}
//take name guess and put in attempt file.
return false ;
}
// bool determineScore()
// { int score; string name; string nameGuess;
// ifstream inFile;
// ofstream outFile;
// inFile.open("namesUsed.txt");
// while (inFile>>name)//new loop input the teamname....
// {
// if (name==nameGuess)//...if the team name equals the users guess....
// { //....increment score and close file mlb teams.txt
// cout <<"Not correct"<< endl;
// return false;
// }
// inFile.close();
// }
// return true;
// }
Nov 12, 2018 at 10:20pm UTC
1 2 3 4 5 6 7 8 9
string enterNameToGuess()
{
string name;
std::cout<<"enter guess name: " ;
std::getline(std::cin,name,'\n' );///use this instead
return name;
}
//use the loop in main
Last edited on Nov 12, 2018 at 10:28pm UTC
Topic archived. No new replies allowed.