c++ - Why won't my do-while loop continue looping? -
i'm working on creating menu error checking , i've come with, can't seem work.
#include <iostream> using namespace std; int main() { char option; // user's entered option saved in variable int error1 = 0; //displaying options menu cout << "there 3 packages available." << endl; cout << "monthly price - price per mb overages (excluding c)" << endl; cout << "a) $15 - $.06 each mb after 200 mb." << endl; cout << "b) $25 - $.02 each mb after 2,000 mb ( approx. 2 gb)." << endl; cout << "c) $50 - unlimited data." << endl; //do-while loop starts here { //prompting user enter option according menu cout << "please enter plan have : "; cin >> option; // taking option value input , saving in variable "option" if(option == 'a' || option == 'a') // checking if user selected option 1 { cout << "you chose a" << endl; error1 = 1; } else if(option == 'b' || option == 'b') // checking if user selected option 2 { cout << "you chose b" << endl; error1 = 1; } else if(option == 'c' || option == 'c') // checking if user selected option 3 { cout << "you chose c" << endl; error1 = 1; } else //if user has entered invalid choice { //displaying error message error1 = 0; cout << "invalid option entered"; } } while(error1 = 0); //condition of do-while loop return 0; }
when typing in incorrect value, output invalid option entered; however, won't loop beginning , prompt user input again.
why doing this?
change
while(error1 = 0); //condition of do-while loop
into this
while(error1 == 0); //condition of do-while loop
in first option assign 0 error1
, error1
being tested boolean means 0 false , non-0 true. sonce condition in while
evaluated false, loop ends.
Comments
Post a Comment