suck with game. please help.

ok here is my stuck I know how to read and write a file but i cant get the same letters on my data file to match my console and i cannot load up and display the board and code. can anyone help me please.
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdlib>
#include <fstream>
using namespace std;
char getMainMenu();
bool checkingChoice(char Choice);
void PlayGame();
void Displayboard();
void SaveGame();
void LoadGame();
int main()
{
string code;
char choice =' ';
//random seed code
unsigned seed =time(NULL);
srand(seed);

while (choice !='Q') //loops until user acknowlgedes correct choice
{
choice=getMainMenu(); // calls function
system("CLS"); // clears screen

switch (choice)
{
case 'P':
cout<< " Play new game"<<endl<<endl;
PlayGame(); //calls functions
Displayboard();
cout<<endl;
break;
case 'R':
cout<<" Resume current game"<<endl;
break;
case 'S':
cout<<" Save current game"<<endl;
SaveGame();
break;
case 'L':
cout<<" Load last saved game"<<endl;
break;
default:
cout << " please enter a correct choice.\n";
break;
case 'Q':
system("pause");
return 0;
}
system("pause");
}
}
char getMainMenu()
{
char choice ='P';
do
{
system("CLS");
cout << " Welcome to CodeBuster! "<<endl;
cout << "-----------------"<<endl<<endl;
cout<< " P - Play new game "<<endl;
cout<< " R - Resume current game " <<endl;
cout<< " S - Save current game " <<endl;
cout<< " L - Load last saved game" <<endl;
cout<< " Q - Quit " <<endl;
cout<< "---------------"<<endl;

if ( !checkingChoice(choice)) //checking for vaild input
cout<<"Please enter a vaild choice from above.\n";
cin>>choice;
}
while ( !checkingChoice(choice));
return toupper (choice); //toupper allows user to enter lowercase letters.
}

bool checkingChoice(char Choice) //checking for error input
{
switch (toupper (Choice))
{
case 'P':
case 'R':
case 'S':
case 'L':
case 'Q':
return true;
default:
return false;
}
}
void PlayGame()
{ char codeLetter1= 65+ (rand ()% 6),
codeLetter2= 65 + (rand ()% 6),
codeLetter3= 65 + (rand ()% 6),
codeLetter4= 65 + (rand ()% 6);;
//generate random numbers
cout<< " SECRET CODE: "<<endl;
cout<<" "<<codeLetter1<<" "<<codeLetter2<<" "<<codeLetter3<<" "<<codeLetter4<<endl;
cout<<endl;
//system ("CLS");
}

void Displayboard( ) // Function to initialize the gameboard.
{
cout<<" YOUR GUSSESS: "<<endl;
// create a blank board
for (int rows=0; rows<12; rows++)
{

for (int cloumns = 0;cloumns<4; cloumns++)
{
cout<< "__ " ;
}
cout<<" P: - "<<"L:-";
cout<< "\n";
}
}

void SaveGame()
{

ofstream outputFile;
outputFile.open ("SaveGame.txt");
outputFile << "- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n"
"- " " - " " - " " -\n";
outputFile.close();
}
Last edited on
Topic archived. No new replies allowed.