1

help me please :sad: if you can find out what's wrong w/ my program, please do tell. thanx very much!

#include <iostream>
using namespace std;



void get_start(int start_hour, int start_min)
//Precondition: User is ready to enter the values for the hour and the minute.
//Postcondition: Values in hours (24-hour notation) and minutes are used as input values
//for the start time of the call.  Returns 1 <= hour <= 24.



void get_end(int end_hour, int end_min)
//Precondition: User is ready to enter the values for the hour and the minute.
//Postcondition: Values in hours (24-hour notation) and minutes are used as input values
//for the end time of the call.  Returns 1 <= hour <= 24.


void peak(int start_hour, int start_min, int end_hour, int end_min)
//Precondition: User has entered the time of the call in hours and minutes.
//Postcondition:  The cost of the call is calculated during peak hours between
//8:00 AM and 6:00 PM at $0.40 per minute.


void non_peak(int start_hour, int start_min, int end_hour, int end_min)
//Precondition: User has entered the time of the call in hours and minutes.
//Postcondition:  The cost of the call is calculated during non-peak hours before
//8:00 AM or after 6:00 PM at $0.25 per minute.


void weekend(int start_hour, int start_min, int end_hour, int end_min)
//Precondition: User has enetered the time of the call in hours and minutes.
//Postcondition:  The cost of the call is calculated during weekends (Saturday and Sunday)
//at $0.15 per minute.



int main()
{
char day, ans;


do
{
cout << "To start calculating the cost of your phone call, please enter the \n";
cout << "day of the week when you made the call \n";
cout << "(enter M for Monday, T for Tuesday, W for Wednesday, H for Thursday, \n";
cout << "F for Friday, A for Saturday, or U for Sunday):" << endl;
cin >> day;


switch (day)
{
case 'M':
case 'm':
cout << "Calls made Mon.-Fri. between 8:00 AM and 6:00 PM (peak hours) \n";
cout << "are $0.40/minute.  Calls made during non-peak hours are $0.25/minute.\n";
cout << "Calls made on Saturdays and Sundays are $0.15/minute.\n";


get_start(start_hour, start_min);
if ((start_hour >= 8) && (start_hour < 18))
peak(start_hour, start_min, end_hour, end_min);
else
non_peak(start_hour, start_min, end_hour, end_min);
break;


case 'T':
case 't':
cout << "Calls made Mon.-Fri. between 8:00 AM and 6:00 PM (peak hours) \n";
cout << "are $0.40/minute.  Calls made during non-peak hours are $0.25/minute.\n";
cout << "Calls made on Saturdays and Sundays are $0.15/minute.\n";


get_start(start_hour, start_min);
if ((start_hour >= 8) && (start_hour < 18))
peak(start_hour, start_min, end_hour, end_min);
else
non_peak(start_hour, start_min, end_hour, end_min);
break;



case 'W':
case 'w':
cout << "Calls made Mon.-Fri. between 8:00 AM and 6:00 PM (peak hours) \n";
cout << "are $0.40/minute.  Calls made during non-peak hours are $0.25/minute.\n";
cout << "Calls made on Saturdays and Sundays are $0.15/minute.\n";


get_start(start_hour, start_min);
if ((start_hour >= 8) && (start_hour < 18))
peak(start_hour, start_min, end_hour, end_min);
else
non_peak(start_hour, start_min, end_hour, end_min);
break;



case 'H':
case 'h':
cout << "Calls made Mon.-Fri. between 8:00 AM and 6:00 PM (peak hours) \n";
cout << "are $0.40/minute.  Calls made during non-peak hours are $0.25/minute.\n";
cout << "Calls made on Saturdays and Sundays are $0.15/minute.\n";


get_start(start_hour, start_min);
if ((start_hour >= 8) && (start_hour < 18))
peak(start_hour, start_min, end_hour, end_min);
else
non_peak(start_hour, start_min, end_hour, end_min);
break;



case 'F':
case 'f':
cout << "Calls made Mon.-Fri. between 8:00 AM and 6:00 PM (peak hours) \n";
cout << "are $0.40/minute.  Calls made during non-peak hours are $0.25/minute.\n";
cout << "Calls made on Saturdays and Sundays are $0.15/minute.\n";


get_start(start_hour, start_min);
if ((start_hour >= 8) && (start_hour < 18))
peak(start_hour, start_min, end_hour, end_min);
else
non_peak(start_hour, start_min, end_hour, end_min);
break;



case 'A':
case 'a':
cout << "Calls made Mon.-Fri. between 8:00 AM and 6:00 PM (peak hours) \n";
cout << "are $0.40/minute.  Calls made during non-peak hours are $0.25/minute.\n";
cout << "Calls made on Saturdays and Sundays are $0.15/minute.\n";


weekend(start_hour, start_min, end_hour, end_min);
break;


case 'U':
case 'u':
cout << "Calls made Mon.-Fri. between 8:00 AM and 6:00 PM (peak hours) \n";
cout << "are $0.40/minute.  Calls made during non-peak hours are $0.25/minute.\n";
cout << "Calls made on Saturdays and Sundays are $0.15/minute.\n";


weekend(start_hour, start_min, end_hour, end_min);
break;



default:
cout << "Please enter a designated letter for a day of the week.\n";


}


cout << "Would you like to calculate the cost of another call?\n";
cout << "Press y for yes, and n for no, then press return: ";
cin >> ans;
} while (ans == 'y' || ans == 'Y');



cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "Good-bye and have a nice day!\n";


return 0;


}


void get_start(int start_hour, int start_min)
{
cout << "Please enter the time you started your call.\n";
cout << "(use 24-hour notation, for example: 3 for 3 AM and 15 for 3 PM)\n";
cout << "Hour: ";
cin >> start_hour;
cout << "Minute: ";
cin >> start_min;
cout << endl;
}


void get_end(int end_hour, int end_min)
{
cout << "Please enter the time you ended your call.\n";
cout << "(use 24-hour notation, for example: 3 for 3 AM and 15 for 3 PM)\n";
cout << "Hour: ";
cin >> end_hour;
cout << "Minute: ";
cin >> end_min;
cout << endl;
}


void weekend(int start_hour, int start_min, int end_hour, int end_min)
{
const double WKND_RATE = 0.15;
double  wknd_cost;
int wknd_time;


get_start(start_hour, start_min);
get_end(end_hour, end_min);


if (start_hour == end_hour)


wknd_time = end_min - start_min;


else


wknd_time = (60 * (end_hour - start_hour)) + start_min + end_min;


wknd_cost = wknd_time * WKND_RATE;
cout << "The cost of your call is: $" << wknd_cost << endl;
}


void peak(int start_hour, int start_min, int end_hour, int end_min)
{
const double PEAK_RATE = 0.40;
double  peak_cost;
int peak_time;


get_start(start_hour, start_min);
get_end(end_hour, end_min);


if (start_hour == end_hour)


peak_time = end_min - start_min;


else


peak_time = (60 * (end_hour - start_hour)) + start_min + end_min;


peak_cost = peak_time * PEAK_RATE;
cout << "The cost of your call is: $" << peak_cost << endl;
}


void non_peak(int start_hour, int start_min, int end_hour, int end_min)
{
const double NONPEAK_RATE = 0.25;
double  nonpeak_cost;
int nonpeak_time;


get_start(start_hour, start_min);
get_end(end_hour, end_min);


if (start_hour == end_hour)


nonpeak_time = end_min - start_min;


else


nonpeak_time = (60 * (end_hour - start_hour)) + start_min + end_min;


nonpeak_cost = nonpeak_time * NONPEAK_RATE;
cout << "The cost of your call is: $" << nonpeak_cost << endl;
}

Edited by happygeek: fixed formatting

Votes + Comments
Use code tags.
4
Contributors
6
Replies
7
Views
13 Years
Discussion Span
Last Post by pseudorandom21
0

this is what the thing says:

ch7prob4.cpp
C:\Documents and Settings\Kulotski\Desktop\ch7prob4\ch7prob4.cpp(19) : warning C4518: 'void ' : storage-class or type specifier(s) unexpected here; ignored
C:\Documents and Settings\Kulotski\Desktop\ch7prob4\ch7prob4.cpp(19) : error C2146: syntax error : missing ';' before identifier 'get_end'
C:\Documents and Settings\Kulotski\Desktop\ch7prob4\ch7prob4.cpp(19) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

ch7prob4.obj - 2 error(s), 1 warning(s)

0

there are variables left to be declared still? i'm not even sure if i've declared them correctly...ugh!

0

well i think that the use of the word "get" two times for two functions has made some error...try with different names and reply

0

well, you're also going to need to pass your variables by reference or pointer, otherwise their contents will not be modified. Pass-by-value copies the variables.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.