I wrote this code and i can't seem to convert the hours to minutes . here is my code
Code:
#include <iostream.h>
int main()
{
// declare variable
int start_hour, start_min;
int stop_hour, stop_min;
float tax;
float discount;
int ampm;
float cost;
int difference,hour_difference, min_difference;
float charges;
int hold;
// get times from user
cout << "Enter Start Hour of call : ";
cin >> start_hour;
cout << "Enter Start Minute of call : ";
cin >> start_min;
cout << "1) AM" << endl;
cout << "2) PM" << endl;
cout << "Please choose your time by entering 1 or 2 : ";
cin >> ampm;
cout << "Enter Stop Hour of call : ";
cin >> stop_hour;
cout << "Enter Stop Minute of cal; : ";
cin >> stop_min;
cout << "1) AM" << endl;
cout << "2) PM" << endl;
cout << "Please choose your time by entering 1 or 2 : ";
cin >> ampm;
// switch statement
switch(ampm)
{
case 1:
cout << "The time of your phone call was in the morning." << endl;
break;
case 2:
cout << "The time of your phone call was in the evening." << endl;
break;
default:
cout << "Please enter a valid number (1 or 2) next time you run program." << endl;
break;
}
// give values to variable & if/else statements and converts min. to hour.
tax = (cost * 0.05);
if (ampm == 1 && start_hour >= 8 && start_min >=00)
cout << "Your phone call will be charged full price. " << endl;
if (ampm == 2 && stop_hour <= 5 && stop_hour <=00)
cout << "Your phone call will be charged full price. " << endl;
if (start_min >=60)
difference = (start_hour + 1);
if (stop_min >=60)
difference = (stop_hour + 1);
if (start_hour >12)
cout << "Invalid start hour." << endl;
if (stop_hour >12)
cout << "Invalid stop hour." << endl;
// convert time
hour_difference = (stop_hour - start_hour);
min_difference = (stop_min - start_min);
cout << "Your call is " << hour_difference << " hour(s) " << min_difference << " minute(s) " << endl;
// phone charges
if (start_hour >=8 && start_min >=00 && stop_hour <=5 && stop_min <=00)
cout << "Your charges are $ " << (min_difference * 0.20) << endl;
cin >> hold;
return 0;
}