Debug and Reformat this program.

Can someone debug, and prototype my program please?
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
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

long callPlayerChoice; //completed code
long playGame; //in progress
string playerName; //completed code
string playerAge; // completed code
long playerGender; //in progress
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; 
     else if(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 ("CLS");
          cout << "How old are you?" << endl;
          getline(cin,playerAge);
          cout << "Nice, " << playerAge << ", thats the perfect age to start this journey. " << endl;
          cin.ignore(80,'\n');
          
          system ("CLS");

          cout << "Please enter a number that corresponds to your gender." << endl << endl;
          cout << "1) Male" << endl;
          cout << "2) Female" << endl;
          cout << "3) Neither" << endl;
          cin  >> playerGender;
          cin.ignore(80,'\n');
          if(playerGender == 1) playerGender = 'Male'; 
          else if(playerGender == 2)  playerGender = 'Female'; 
          else playerGender = 'Neither';
          cout << "Welcome " << playerName << ", age " << playerAge << ", thats a perfect name for a " << PlayerGender << ", I wish you luck on your journey." << endl;
          
          }
          
     system ("PAUSE");
     return 0;
     }
Last edited on
What's wrong with it?
system ("Anything") should not be used.

playerGender is an integer type, and can't be used to store a string (line 65).

Why do you have 3 variables for the player's choice, each of which you assign a different number when you get their choice? Either test the variable containing their choice directly, or use 3 booleans.

Try to avoid global variables.

Age should not be a string.
I'm also a beginner, so maybe you shouldn't listen to what I have to say.

Still, I looked this over and couldn't figure out why you made gender a long when it could simply be an int, and your if statement needs to have an else for what would happen given an invalid value. If you want the pause at the end of your program, I agree with BlackSheep that you should never use system commands (we left batch files for this...) and instead end your program like this:
1
2
3
4
//here is your program
cin.get();
return 0;
}
Topic archived. No new replies allowed.