Can somebody help me organize my program so far, so that it has functions at top, and there definitions at the bottom, that way i can call any part of my program where it is needed. I also need help calling them to make them run like this program does. Just post the rewritten program please.
//////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
long callPlayerChoice; //completed code
long playGame; //in progress
string playerName; //completed code
long Instructions; //in progress
long Quit; //completed code
int main()
{
cout << "Please enter a number for the task you want to complete." << endl << endl;
cout << "1) Play" << endl;
cout << "2) Instructions" << endl;
cout << "3) Quit" << endl;
cin >> callPlayerChoice;
cin.ignore(80,'\n');
////////////////////////////////////////////////////////////////////////////
if(callPlayerChoice == 1)
{
playGame = 1;
}
elseif(callPlayerChoice == 2)
{
Instructions = 2;
}
else{Quit = 3;
};
/////////////////////////////////////////////////////////////////////////////
if(Quit == 3)
{
system ("CLS");
cout << "Thanks for playing!!! Hope you enjoyed!!!" << endl;
cin.get();
};
/////////////////////////////////////////////////////////////////////////////
if(Instructions == 2)
{
system ("CLS");
cout << "There are currently no instructions for this program." << endl;
cin.get();
};
//////////////////////////////////////////////////////////////////////////////
{
if(playGame == 1)
{
system ("CLS");
cout << "Welcome to the game! Since you are starting on your journey," << endl;
cout << "let me know a little bit about you.";
cout << " What is your full name?" << endl << endl;
getline(cin,playerName);
cout << "Nice to meet you " << playerName << "." << endl;
cin.ignore(80,'\n');
}
}
///////////////////////////////////////////////////////////////////////////////
system ("PAUSE");
return 0;
};
Eh... Thats a tad bit difficult to understand. Maybe if you indented everything inside each block by about 4 spaces I'd be able to help some more. What I can see here though is that you seem to have ended your main function with };. Does this compile without errors?
Yes ... agree with Buffer it is a tad difficult as your code does not appear to possess any functions other than get(), ignore() and getline() which do not require this treatment. I'm supposing that you want your function prototypes above "int main ()" and their definitions below "int main ()".
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
long callPlayerChoice; //completed code
long playGame; //in progress
string playerName; //completed code
long Instructions; //in progress
long Quit; //completed code
int main()
{
cout << "Please enter a number for the task you want to complete." << endl << endl;
cout << "1) Play" << endl;
cout << "2) Instructions" << endl;
cout << "3) Quit" << endl;
cin >> callPlayerChoice;
cin.ignore(80,'\n');
if(callPlayerChoice == 1) playGame = 1;
elseif(callPlayerChoice == 2) Instructions = 2;
else Quit = 3;
if(Quit == 3)
{
system ("CLS");
cout << "Thanks for playing!!! Hope you enjoyed!!!" << endl;
cin.get();
}
if(Instructions == 2)
{
system ("CLS");
cout << "There are currently no instructions for this program." << endl;
cin.get();
}
if(playGame == 1)
{
system ("CLS");
cout << "Welcome to the game! Since you are starting on your journey," << endl;
cout << "let me know a little bit about you.";
cout << " What is your full name?" << endl << endl;
getline(cin,playerName);
cout << "Nice to meet you " << playerName << "." << endl;
cin.ignore(80,'\n');
}
system ("PAUSE");
return 0;
}