Question

This is a very short trivia game. See if the user can guess the year that...

This is a very short trivia game. See if the user can guess the year that MDC (formerly Dade County Junior College) first started offering classes (1960). If the user guesses incorrectly, ask if they want another attempt. Once the user gets it right, report the number of guesses needed and end the program.

Initial Output:

MDC was originally named Dade County Junior College.

Output (per loop)

In what year were classes first offered? [user types: 1980]

That answer is incorrect. Do you want to try again? [user types: y]

In what year were classes first offered? [user types: 1960]

Your answer is correct! It took you 2 tries to guess it.

Notes and Hints:

1) You can use whatever loop you feel is best

2) You must accept the upper and lower case versions of Y and N in the user's reply

3) The program must end when the user gets it right. Do not ask if they want to continue.

Starter Code:

// CONSTANTS AND VARIABLES
  
// INITIAL MESSAGE
std::cout << "MDC was originally named Dade County Junior College.\n";

// LOOP WHILE USER WANTS TO KEEP GUESSING
  
std::cout << "In what year were classes first offered? ";
  
std::cout << std::endl; // For Mimir

std::cout << "That answer is incorrect. Do you want to try again? ";

std::cout << std::endl; // For Mimir

std::cout << "Your answer is correct! It took you " << YOUR_CODE << " tries to guess it.";
  

Homework Answers

Answer #1

#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
int year,i=0;
char ch;
cout << "MDC was originally named Dade County Junior College.\n";
do{
i++;
cout << "In what year were classes first offered? ";
cin>>year;
if(year==1960)
{
cout<<"Your answer is correct! It took you "<<i<<" tries to guess it.";
ch='n';
}
else{
cout<<"That answer is incorrect. Do you want to try again?";
cin>>ch;
}
}while(ch=='y'|| ch=='Y');
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT