Hey there guys, I'm just learning C so I tend to throw in a bunch of extra stuff just to make sure I know how to use it correctly (so don't hound on me about using a variable's memory address instead of the actual variable heh) and I'm trying to set up this while loop using a bolean expression. Anyway this is the whole program:
Thing is, that it won't combile the while loop and I'm not sure why. I'm sure it's simple syntax I'm messing up but I'm stumpedCode:#include <iostream> using namespace std; int main() { int x; //defines x int *p; //defines p as a pointer p = &x; //sets the pointer the the memory address of variable x cout<<"Hey there! My name is Mr. Computer, how are you today?\n"; cout<<"1. I'm great! :D\n"; cout<<"2. I'm good.. :)\n"; cout<<"3. Awful! :(\n"; cin>> x; cin.ignore(); while (*p = 1 || *p = 2 || *p = 3) { //loop that will ensure a recognizable answer cout<< *p <<" is not a valid input, please input a number between 1-3."; cin>> x; } switch (*p) { //Sets up a switch case for variable x based on it's address in memory being displaed as an intenger case 1: cout<<"Good ........!"; break; case 2: cout<<"Cool"; break; case 3: cout<<"Well I hope it gets better..."; break; default: cout<<"Error\n"; break; } cin.get(); }Thanks for taking the time to read and for any input you could provide!
-Dr^ZigMan



LinkBack URL
About LinkBacks
Thanks for taking the time to read and for any input you could provide!



