I have just a quick question that someone could hopefully solve for me in a matter of seconds. Below is a text based trivial pursuit program (as of right not there isn't much too it, but i need to fix this problem first).
The problem lays within the case 'y' of the switch structure. When the user types in his or her name, instead of showing in the file a blank space shows. I have tried everything, changing the dummy string, taking it out, moving things around, nothing seems to work. Can someone take a look for me?
Code:
// Brandon Blincoe
// Trivial Pursuit
// The game of trivial pursuit using files storing data
// CREDITS
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <assert.h>
using namespace std;
using std::string;
int main()
{
string name;
string dummy = "";
char user_entry;
char answer;
int user_entry_2 = 0;
int counter = 1;
int player_count = counter;
ofstream responses;
cout << "Trivial Pursuit\n\n";
cout << "Would you like to begin? <Y/N>";
cin >> user_entry;
responses.open("RESPONSE.DAT", ios::out);
assert(!responses.fail());
do
{
switch(user_entry)
{
case 'Y':
case 'y':
cout << "Player " << counter << ": ";
getline(cin, name);
responses << name << "\n";
getline(cin, dummy);
cout << "Add another player? <Y/N>";
cin >> user_entry;
counter++;
break;
case 'N':
case 'n':
system("CLS");
while(player_count < counter)
{
if(player_count == 1) // begins questions for player 1
{
cout << "Player " << player_count << " begin.\n";
cout << "Question 1:\n";
cout << "When x squared minus four is factored, what is one value of x?\n";
cout << "a) (1)";
cout << setw(20) << "b) (2)\n";
cout << "c) (-4)";
cout << setw(19) << "d) (4)\n";
cout << "Your Answer is: ";
cin >> answer;
cout << "\n\n";
responses << answer << "\n";
cout << "Question 2:\n";
cout << "Why doesn't oil and water(H20) mix?\n";
cout << "a) Molecular Formulas differ";
cout << setw(29) << "b) They don't feel like it\n";
cout << "c) Like dissolves like";
cout << setw(22) << "d) Who cares?\n";
cout << "Your Answer is: ";
cin >> answer;
responses << answer << "\n";
player_count++;
}
else
{
system("CLS");
cout << "Player " << player_count << " begin.\n";
cout << "Question 1:\n";
cout << "When x squared minus four is factored, what is one value of x?\n";
cout << "a) (1)";
cout << setw(20) << "b) (2)\n";
cout << "c) (-4)";
cout << setw(19) << "d) (4)\n";
cout << "Your Answer is: ";
cin >> answer;
cout << "\n\n";
responses << answer << "\n";
cout << "Question 2:\n";
cout << "Why doesn't oil and water(H20) mix?\n";
cout << "a) Molecular Formulas differ";
cout << setw(29) << "b) They don't feel like it\n";
cout << "c) Like dissolves like";
cout << setw(22) << "d) Who cares?\n";
cout << "Your Answer is: ";
cin >> answer;
responses << answer << "\n";
player_count++;
}
}
cout << "Congratulations! Your done! <PRESS 1 to QUIT>";
cin >> user_entry_2;
break;
}
}
while(user_entry_2 < 1);
system("CLS");
responses.close();
assert(!responses.fail());
return 0;
}