how to?? last one ^_^


switch(choice)
	{
		case'A':
		case'a':
			cout<<"Enter value in KM: ";
			cin>>km;
			m=km*1000;
			cout<<km<<" KM is equal to "<<m<<" M\n";
			break;
		case'B':
		case'b':
			cout<<"Enter value in M: ";
			cin>>m;
			cm=m*100;
			cout<<m<<" M is equal to "<<cm<<" CM\n";
			break;
		case'C':
		case'c':
			cout<<"Enter value in CM: ";
			cin>>cm;
			mm=cm*10;
			cout<<cm<<" CM is equal to "<<mm<<" MM\n";
			break;
		case'D':
		case'd':
			return 0;
			break;
		default:
			cout<<"Invalid Input\nEnter Choice again: ";
			cin>>choice;
	}
	}while (choice=='A'||choice=='a'||choice=='B'||choice=='b'||choice=='C'||choice=='c'||choice=='D'||choice=='d');

Im trying to make the user input again until the value becames valid

the problem is when i try it, it only ask 2 times then exits...

this is the last problem thats being a burden to my sleep Y_Y

help will be much appreciated~
I'm assuming that while is at the end of a do ... while statement. Anyway, if the user enters invalid input (not a/b/c/d), then you will not loop.
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	int invalid = 0; //I know you don't know about bool yet. 
	
	do 
	{
		invalid = 0;
		char input;
		cin >> input;
		switch (input) 
		{
			case 'A':

				break;
			//
			//...
			//
			default:
				cout << "Invalid Input\nEnter Choice again: ";
				invalid = 1;
				break;
		} //end switch
		
	} while (invalid);
Your while loop will only loop if they have entered a valid choice. Is that what you want?
Perhaps you need to look at your logic again. I have to say I'm not 100% sure what you're trying to do, but I'll take a stab...

1. DO: Get a character from input, assign that value to 'choice'
- Keep repeating WHILE (tolower(choice) != 'a') || (tolower(choice) != 'b' etc...
2. Process the valid character like you're doing in your case statements

If you want to repeat the entire process, you need to put a loop around the entire thing.

Hope that helps. Feel free to post your next attempt if you're still stuck...
@firedraco:

you got me there..
that answers my question~

@Grey Wolf:

Dude thx thats what i wanna see XD


Anyways all did some help so...
THX y all~
Topic archived. No new replies allowed.