c++ - Input Validating functions -
i'm new c++ , coding in general. currently, struggling create "mad lib" program asks user inputs (2 different nouns , 2 different adjectives) , uses inputs generate lines " . looks ."
when user runs program, supposed asked "do want play game? enter y yes , n no". if user responds y, madlib function should run , should give inputs. once story finished , returned user, should prompted again whether or not want continue playing (again, y yes , n no). should able play game many times want until answer 'n'. far, last part has been biggest struggle. know how create program within 1 main function, goal make sort of input validation n , y function can called main function. ideas? here's have far:
#include <iostream> using namespace std; int madlib(){ string noun, adjective, noun1, adjective1; cout << "enter noun" << endl; cin >> noun; cout << "enter adjective" << endl; cin >> adjective; cout << "enter noun" << endl; cin >> noun1; cout << "enter andother adjective" << endl; cin >> adjective1; cout << noun << " " << adjective << ". looks " << adjective1 << " " << noun1 << "." << endl; } int main(){ char response; cout << "type y yes , n no" << endl; cin >> response; while (response == 'y'){ int madlib(); cout << "play again?" << endl; cin >> response; } if (response == 'n'){ cout << "goodbye." << endl; } }
while (response == 'y'){ int madlib();
inside while
loop, declares function called madlib()
.
note not same thing executing function called madlib()
. declaration. statement of fact exists.
however, proclaiming world, function exists, not sufficient. prefer execute it, instead. in case, be:
madlib();
Comments
Post a Comment