if statement - Else component of if/else not executing (C++) -
i have relatively large program , not of relating question, particular bit stumping me. below int main:
int main () { int casenumber ; string clientname, clientemail, subject, path, filename, firsttime ; //creates string path of files created , python project stored (with .exe) path = _pgmptr ; filename = "emailgenerator.exe" ; filename.length() ; path.erase(path.length() - filename.length()) ; //checks first time use customizing cout << "welcome ticket email generator.\n\n" << "if first time using program,\nplease enter y customize personal details.\n" << "if not, enter other character.\n" ; cin >> firsttime ; cin.ignore() ; if (firsttime == "y" || firsttime == "y") { //save sender email (defaults morgan_wallace@cable.comcast.com - creator) setsender (path) ; //verifies signature file desired (to saved future) char ready = 'n' ; while (!(ready == 'y' || ready == 'y')) { std::cout << "\nplease modify signature.txt file located in " + path << endl << "enter y when done.\n" ; cin >> ready ; cin.ignore() ; } } //email "to" field: setto (path) ; //email "subject" field: setsubject (path) ; //email "body" field: std::cout << "\nplease provide following information body of email:" << endl ; //create standard time-based greeting @ top of message settoname (path) ; //select message type & compose body of message ofstream scriptfout (path + "script.txt") ; std::cout << "\nplease select case type menu:" << endl << endl ; casetypemenu(scriptfout) ; scriptfout.close() ; //compose full body , add signature setbody (path) ; std::cout << "would review email before sending? y/n " ; char reviewchar ; cin >> reviewchar ; cin.ignore() ; if (reviewchar == 'y' || reviewchar == 'y') { review (path) ; } else if (reviewchar == 'n' || reviewchar == 'n') { //run email sender (python program) string pythonpathstring = path + "emailproj/emailproj/emailproj.py" ; string pythonstring = "c:/python27/python.exe " + pythonpathstring + " " + path ; system(pythonstring.c_str()) ; //exit program string ; std::cout << "enter exit\n" ; cin >> ; cin.ignore() ; } else { cout << "invalid entry review: " + reviewchar << endl ; //exit program string ; std::cout << "enter exit\n" ; cin >> ; cin.ignore() ; } return 0 ; }
my specific issue last if/else (everything else executes expected):
std::cout << "would review email before sending? y/n " ; char reviewchar ; cin >> reviewchar ; cin.ignore() ; if (reviewchar == 'y' || reviewchar == 'y') { review (path) ; } else if (reviewchar == 'n' || reviewchar == 'n') { //run email sender (python program) string pythonpathstring = path + "emailproj/emailproj/emailproj.py" ; string pythonstring = "c:/python27/python.exe " + pythonpathstring + " " + path ; system(pythonstring.c_str()) ; //exit program string ; std::cout << "enter exit\n" ; cin >> ; cin.ignore() ; } else { cout << "invalid entry review: " + reviewchar << endl ; //exit program string ; std::cout << "enter exit\n" ; cin >> ; cin.ignore() ; }
if input 'h', or character not y, y, n, or n, not print error script inappropriate answer. prints line of code (something printed screen cout in earlier portion of code) , "enter exit" , waits input. if input 'g', skips error message altogether , prints "enter exit line" , waits input.
the point of last if/else allow user view message, , decide whether send it, edit portions of it, or disregard completely. purposes of error checking, handle inputs not y, y, n, , n, though theoretically there should no other inputs.
your problem here:
cout << "invalid entry review: " + reviewchar << endl ;
when use plus sign adding value of integer pointer, not concatenating strings.
try this:
cout << "invalid entry review: " << reviewchar << endl ;
Comments
Post a Comment