Urgent Help needed!

Nov 2, 2015 at 11:25am
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 Nov 2, 2015 at 12:36pm
Nov 2, 2015 at 12:02pm
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.
Nov 2, 2015 at 12:26pm
Thanks Mikey :) I actually sorted it out myself but I need another help instead!
Nov 2, 2015 at 12:34pm
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/
Nov 2, 2015 at 12:38pm
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.


Nov 2, 2015 at 12:40pm
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.
Nov 2, 2015 at 12:44pm
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?
Nov 2, 2015 at 2:26pm
Lol, solved myself.
Topic archived. No new replies allowed.