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
|
//Program to display months of the year and the number of days in each month
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
using namespace std;
int main()
{
srand((unsigned)time(NULL));
int Month,CorrectAns,score=0;
const int Num_Month=12;
string name[Num_Month]={"January","February","March",
"April", "May", "June",
"July", "August", "September",
"October", "November","December"};
int days[Num_Month]={31,28,31,30,31,30,31,31,30,31,30,31};
for(int Question=1;Question<=10;Question++)
{
for(int month=0;month<=Num_Month;month++)
{
int choice=1+rand()%12;
cout<<"How many days are there in the month of "<<name[choice-1]<<" ?";
cin>>Month;
CorrectAns=days[choice-1];
if(CorrectAns==Month)
{
cout<<"Correct!"<<endl;
score+=10; //Add 10 pts to score
}
else
{
cout<<"No "<<name[choice-1]<<" has "<<CorrectAns<<"days."<<endl;
}
cout<<"Total score is: "<<score<<endl;
} }
}
|