Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help with time checking.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi all,
I am trying to make a program that will allow users to add a course if it does not conflict with any existing course. The program should then check with the existing two courses to see if there is a conflict in time. If there is a conflict, the course will not be added, otherwise added. Finally the updated course list will be displayed.
This is what I got so far and I have reach my limit.
The problem I have is getting C++ to check to see if the time the user input is in conflict with with any existing course.Other than that I know how to do.I have tried the if-statement but with no luck.Can anyone help me out here?

#include<iostream>

struct Time
{ int Hrs;
int Mins;
};

{
char CourseID[10];
Time StartTime;
int Length;
};


Time SetTime();
void PrintTime(Time );

void main()
{//Declaration of an array of type Course of size 5 with first two elements initialized.
Course Current[5] = { {&quot;MTH101&quot;, 9, 30, 75}, {&quot;M212&quot;, 14, 0, 110} };

cout<<&quot;\nEnter course number: &quot;;
cin>>Current[2].CourseID;
Current[2].StartTime = SetTime();
cout<<&quot;\nEnter the length in minutes: &quot;;
cin>>Current[2].Length;



}


//function definitions
Time SetTime()
{ Time T;
cout <<&quot;Enter hours (in military) and minutes separated by a space: &quot;;
cin >> T.Hrs >> T.Mins;
return T;
}

void PrintTime(Time T)
{ if (T.Hrs != 12)
cout << T.Hrs%12 <<':';
else
cout <<T.Hrs <<':';
if (T.Mins < 10 )
cout << '0' <<T.Mins;
else
cout << T.Mins;
if (T.Hrs < 12)
cout <<&quot; AM&quot;;
else
cout <<&quot; PM&quot;;
}

 
say you input a time to starttime:
if (starttime != current[1].starttime && starttime != current[0].starttime){
// add the course
}

you can use the loop to test if there are more courses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top