Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ok here\'s an outline of what the program asks 1.A user input a series of times

ID: 3528792 • Letter: O

Question

Ok here's an outline of what the program asks


1.A user input a series of times (24 clock) within one day. Therefore all times must be entered (00 34) <<< in that format. If the hour time is less than 0 or greater than/equal to 24 the program should tell the user invalid time entered. Also if a minute time of less than 0 or greater than/equal to 60 is entered the program should tell the user invalid time entered----------------------

2 If the user inputs 99 99 as the time then the loop of asking user to input time ends-----------------

3. The program must keep track and then display at the end of all the valid and invalid times entered---------------------

4. The program must keep track and then display at the end the shortest gap between two times, the largest gap between two times and the average gap between all the times(all in minutes)-----------------------------

5. If a valid time is entered and it is less than the time entered before (ie user enters 15 34 and before that entered 16 34, then that means 23 hours have gone by. Not -1 hours)----------------------------

6. All invalid tmes should be ignored when it comes to determining the gaps.---------

7. If only 1 valid time is entered, then it should only display the stat of how many valid/invalid times were entered ------------


Ok so I'll post what I have so far, I'm stuck with the math when it comes to determining the gap between two times and knowing which one is the shortest gap, larges gap etc. So I didn't involve it in this version I'm posting. Please help!


-----

Heres the code

// Variable Declarations
double x; // minutes
double y; // hours
double a = 0; //keeps track of TIMES entered
double b = 0; //keeps track of valid times entered
double c = 0; //keeps track of invalid times entered
double d; //gap between hour time
double e = 0;//gap between hour time
double f; //gap between minute time
double g = 0;//gap between minute time
// Asks user to input values
cout<<"Input time (hours/minutes)(99 99 to exit): ";
cin>>x>>y;

//looping the question
while (x != 99 && y != 99){
a = a + 1;

//invalid time entered
if (x < 0 || x >= 24 || y < 0 || y >= 60) {
cout<<"Invalid Time Entered"<<endl<<endl;
cout<<"Input time (hours/minutes)(99 99 to exit): ";
cin>>x>>y;
c = c + 1;
}//end invalid if
else{
}

//asks user to input time
cout<<"Input time (hours/minutes)(99 99 to exit): ";
cin>>x>>y;
}
// math
b = a - c;


cout<<endl;
//statistics
if (a = 0){
cout <<"The number of valid times entered: " <<b << endl;
cout << "The number of invalid times entered: " << c << endl;
cout << "No other stats can be provided" <<endl;
}else {
cout << "The number of valid times entered: " << b << endl;
cout << "The number of invalid times entered: " << c << endl;
cout << "The largest gap between two busses is: " << e << " hours and " << g << " minutes" << endl;
}//Stops program
system("PAUSE"); return 0;

Explanation / Answer

Why dont you do it this way...

If a,b are hours and minutes entered previosuly

c,d are hrs and minutes entered now,

to find which one is big,


change the data type to int first

int gap_hrs,gap_min,,chk;

chk =(a*60+b)-(c*60+d);

if (chk<0){

chk = 24*60+chk; // Depending on the POINT 5 GIVEN

}

gap_hrs = chk/60; //Difference in hrs

gap_min = chk`; //DIfference in minutes

}



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote