Please use this format #include <iostream> #include <string> using namespace std
ID: 3648642 • Letter: P
Question
Please use this format
#include <iostream>
#include <string>
using namespace std;
int main(){
}
Explanation / Answer
please rate - thanks
you didn't explain the data in the struct, so I guessed
#include <iostream>
#include <string>
using namespace std;
struct Time
{int day;
bool pm;
int hour;
int min;
};
void getInput(Time& );
bool ok(const Time&);
int main(){
int i,n;
Time t;
cout<<"how many sets of data do you have? ";
cin>>n;
for(i=0;i<n;i++)
{ getInput(t);
if(ok(t))
cout<<"Your data is a correct time: ";
else
cout<<"Your data is not a correct time: ";
}
system("pause");
return 0;
}
void getInput(Time& t )
{int temp;
cout<<"Enter day of week(0-6): ";
cin>>t.day;
cout<<"Enter 1 for AM, 2 for PM: ";
cin>>temp;
if(temp==1)
t.pm=false;
else
t.pm=true;
cout<<"Enter hour(1-12): ";
cin>>t.hour;
cout<<"Enter minute(0-59): ";
cin>>t.min;
}
bool ok(const Time& t)
{if(t.day<0||t.day>6)
return false;
if(t.hour<1||t.hour>12)
return false;
if(t.min<0||t.min>59)
return false;
return true;
}