|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
loop problem
having a problem with this small c++ program im writing.
i'm getting an error saying Lvalue required at the first while statement this program loops printing just the message until the user enter 'n' or 'N'. If the user enters a character other than 'n' , 'N' , 'y' , 'Y' the message invalid selection is entered and the prompt should be redisplayed can anyone please help? #include <iostream.h> # include <stdlib.h> char ch; void main() { while (ch=!'n' || ch=!'N') { cout << "Do you really want to run this program? (yes/no)\n "; cin >> ch ; if (ch!='y' || ch!='Y' || ch!='n' || ch!='N') { cout << "Invalid selection\n" ; } } if (ch=='n' || ch=='N') { exit(1); } } |
|
#2
|
||||
|
||||
|
Code:
#include <iostream.h>
int main() {
char ch='\0';
while (ch!='y' && ch!='Y') {
cout << "Do you really want to end this program (y/n)?";
cin >> ch;
if (ch!='Y' && ch!='y' && ch!='N' && ch!='n')
cout << "Invalid selection.\n";
}
cout << "End of program.\n";
return(1);
}
|
|
#3
|
||||
|
||||
|
Quote:
The not-equal operator is "spelled" as != instead of as =!. You seem to use it the right way further down in your code.
__________________
"A poor programmer is he who blames his tools." http://analyser.oli.tudelft.nl/ |
|
#4
|
|||
|
|||
|
while(toupper(ch)!='Y')//get rid of all lower case
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions. Frank Zappa |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > loop problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|