subprograms
Jul 26, 2012 at 11:02am UTC
I'm supposed to rewrite my quiz program so that the code that allows it to output the questions, allows user input for the answer, and then notifies the user if it's correct or incorrect is written all in a SUBPROGRAM. While my original program worked, I've tinkered with this forever and I don't know what code to put where (and as you can see, I've moved some stuff around):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#include <cctype>
void getAnswer()
{
while (true )
{
string city, lastName, year;
cout << "In what city was Apple Inc. established?: " ;
getline(cin, city);
cout << endl << endl;
cout << "What is the last name of Steve Jobs' biological father?: " ;
getline(cin, lastName);
cout << endl << endl;
cout << "In which year was Apple Computer Inc. established?: " ;
cin >> year;
cout << endl << endl;
} // while
} // getPassword
class toLower {public : char operator ()(char c) const {return tolower(c);}};
int main()
{
// string city;
// cout << "In what city was Apple Inc. established?: ";
// getline(cin, city);
transform(city.begin(), city.end(), city.begin(), toLower());
if (city == "cupertino" ) {
cout << "Correct!" << endl; }
else {
cout << "Incorrect." << endl; }
cout << endl << endl;
// string lastName;
// cout << "What is the last name of Steve Jobs' biological father?: ";
// getline(cin, lastName);
transform(lastName.begin(), lastName.end(), lastName.begin(), toLower());
// if (lastName == "jandali") {
cout << "Correct!" << endl;}
else {
cout << "Incorrect." << endl; }
cout << endl << endl;
// int year;
// cout << "In which year was Apple Computer Inc. established?: ";
// cin >> year;
if (year == 1976) {
cout << "Correct!" << endl; }
else {
cout << "Incorrect." << endl; }
cout << endl << endl;
return 0;
}
Topic archived. No new replies allowed.