Urgent Help needed!

Problem: Would like to continue this loop until I get a 'N or 'n' response from the user.
This is the final problem I encounter then I am done with the assignment, please help me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
char ch;
	char response;
	
	do
	 
	{
	
	cout << "Welcome to ABC credit card company\n\n";
	cout << "Enter credit card no: ";
	cin >> cardNumber1 >> ch >> cardNumber2 >> ch >> cardNumber3 >> ch >> cardNumber4;
	
	cout << "Another card (y/Y/n/N): "
	response = getchar();
	getchar ();
	while (response == 'Y' || response == 'y');
         }

	
	
Last edited on
If you want your function to return an int value, then declare it with that type.

If you don't want your function to return any value, then declare it as void.

If you know how to write a function that returns an int (and I assume you do, since you seem to be writing them), then you should be able to write a function that returns a bool instead of an int.
Thanks Mikey :) I actually sorted it out myself but I need another help instead!
You need to close your do...while block. I don't see any closing brace.

If you used a sensible indentation style, it would make it much easier for you to see mistakes of this kind.

A couple of things:

1) Please don't delete questions once you've had them answered. It makes the thread confusing, and makes it useless as a resource for others. If you have a new problem, there's nothing wrong with adding it to the thread as a new reply.

2) Please use code tags when posting code, to make it easier to read:

http://www.cplusplus.com/articles/z13hAqkS/
Hi Mikey, so sorry about that. Thought it would be clearer for viewers to see the first post.

I am just a beginner for c++..

What I am intending to do right now after the

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
char ch;
	char response;
	
	do
	 
	{
	
	cout << "Welcome to ABC credit card company\n\n";
	cout << "Enter credit card no: ";
	cin >> cardNumber1 >> ch >> cardNumber2 >> ch >> cardNumber3 >> ch >> cardNumber4;
	
	cout << "Another card (y/Y/n/N): "
	response = getchar();
	getchar ();
	while (response == 'Y' || response == 'y');
          else if (response == 'N' || response == 'n');
          return 0;
                 }



ughhhhhhh, Help.


You need to re-read my answer, as you haven't fixed the problem I mentioned.

Also, what is that "else" doing in line 16? There's no "if" statement matching it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
     char ch;
	char response;
	
	do
	 
	{
	
	cout << "Welcome to ABC credit card company\n\n";
	cout << "Enter credit card no: ";
	cin >> cardNumber1 >> ch >> cardNumber2 >> ch >> cardNumber3 >> ch >> cardNumber4;
	
	cout << "Another card (y/Y/n/N): "
	response = getchar();
	getchar ();
         }

	while (response == 'Y' || response == 'y');
        
                


Sorry, thought that else would also work since I was thinking of .. "If I press Y, I get this.. Else if I press N, I won't get this. But yeah I know it's for if-else statement, sorry about that.

How can I continue with this?
Lol, solved myself.
Topic archived. No new replies allowed.