Console Application Skipping Steps

Hello everyone, I'm new here. New to C++ and programming in general as well.

My goal is to eventually create a full feature d20 program for everything from character sheets to campaign creation. Since I am new to coding I need to start small. So I'm just doing a mock console program using what I've been able to learn so far.

The program launches fine, gets the player name, then speeds through the rest of the code. It doesn't ask for anything else. Just ends. This is the code. I'm stumped.

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
// Program will get the player and character name then verify them.
// The program will then establish attributes and verify those.

#include <iostream>

int main()
{
	std::cout << "Welcome to Raven Tabletop Assist" << std::endl;

	// Declare variables for player name and character name.
	char cPlayerName;
	char cCharacterName;
	char vNo; // Generic Answer Variable
			
			// Get Player name:
			std::cout << "Please enter your name: ";
			std::cin.get (cPlayerName);
			std::cout << std::endl << "Thank you." << std::endl;

			// Get Character Name:
			std::cout << cPlayerName << " please enter your character name: " << std::endl;
			std::cin.get (cCharacterName);
			std::cout << std::endl << "Thank you." << std::endl;

	// Input varification: Player Name
	std::cout << "Your name is: " << cPlayerName << std::endl << "Is this correct? Y/N: ";
	std::cin.get (vNo);
	
	// Check answer, if N retrieve correct player name. If yes, move on.
	if (vNo == 'N')
		{
			std::cout << "Please enter your name: ";
			std::cin.get (cPlayerName); // Retrieve player name
			std::cout << std::endl << "Thank you." << std::endl;
		}

		else

	// Input varification: Character Name
	std::cout << "Your character name is: " << cCharacterName << std::endl << "Is this correct? Y/N" << std::endl;

}
Any particular reason your using chars? I would use strings instead... If you replace the variable type of cPlayerName & cCharacterName to string and use std::getline(std::cin,cPlayerName) instead of std::cin.get(); your code should work fine.
Thank you. It's simply out of ignorance that I wasn't using strings. As I go along I'm looking stuff up. It's a lot to take in. My code looks like this now:

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
// Program will get the player and character name then verify them.
// The program will then establish attributes and verify those.

#include <iostream>
#include <string>
using namespace std;

int main()
{
	cout << "Welcome to Raven Tabletop Assist" << endl;

	// Declare variables for player name and character name.
	string cPlayerName;
	string cCharacterName;
	char vNo; // Generic Answer Variable
			
			// Get Player name:
			cout << "Please enter your name: ";
			getline (cin,cPlayerName);
			cout << endl << "Thank you." << endl;

			// Get Character Name:
			cout << cPlayerName << " please enter your character name: " << endl;
			getline (cin,cCharacterName);
			cout << endl << "Thank you." << endl;

	// Input varification: Player Name
	cout << "Your name is: " << cPlayerName << endl << "Is this correct? Y/N: ";
	cin.get (vNo);
	
	// Check answer, if N retrieve correct player name. If yes, move on.
	if (vNo == 'N')
		{
			cout << "Please enter your name: ";
			getline (cin,cPlayerName); // Retrieve player name
			cout << endl << "Thank you." << endl;
		}

		else

	// Input varification: Character Name
	cout << "Your character name is: " << cCharacterName << endl << "Is this correct? Y/N" << endl;

}


It now gets to the cPlayerName verification then quits out on me after an answer has been given. I'm looking for an answer right now, but is there a different way I should be setting up my if statement?


I started trying to learn a programming language several months ago, java. Work got in the way though. As of right now I'm looking at being unemployed for awhile so I want to give it another good shot.
Try this
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
// Program will get the player and character name then verify them.
// The program will then establish attributes and verify those.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	cout << "Welcome to Raven Tabletop Assist" << endl;

	// Declare variables for player name and character name.
	string cPlayerName;
	string cCharacterName;
	
	//Name processing
	std::cout<<"Please enter your name: ";
	
	std::string dec;
	getline(cin,cPlayerName);
	cout << "Your name is: " << cPlayerName << endl << "Is this correct? Y/N: ";
	getline(cin,dec);
	if(dec == "N")
	{
		cout<<"Please enter your name: ";
		getline(cin,cPlayerName);

	}
		
	cout<<"Thank You!"<<endl;

	//Character Name processing
	std::cout<<cPlayerName <<" please enter you character name: ";
	
	
	getline(cin,cCharacterName);
	cout << "Your character name is: " << cCharacterName << endl << "Is this correct? Y/N: ";
	getline(cin,dec);
	if(dec == "N")
	{
		cout<<"Please enter your  character name: ";
		getline(cin,cCharacterName);
	}
		
	cout<<"Thank You!"<<endl;

	// Displaying name and character name
	cout << "Your name is: " << cPlayerName << endl << "Your character name is  " <<cCharacterName<< endl;

	
	char c[10];
	std::cin.getline(c,10);

}
Didn't have time to sit down today and mess around with my code. Had bowling and my team took second out of twenty! Unfortunately I won't be able to sit down with this until tomorrow for research and what not.

I pretty understand everything in there except for three things:

1. #include <sstream> what is <sstream>?

2. your using 'dec' as a variable, it's not a command, right?

3. char c[10] I see your declaring 'c' as a character(?) but what is the [10] doing?

Thank you for taking the time to write that up.
I've figured out what everything in there is doing, although I'm still a little unclear on <sstream>. Thank you for the help.
Topic archived. No new replies allowed.