d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Any Help Would Be Appriciated > Kind Of Fun Tho..
Add Reply New Topic New Poll
Member
Posts: 1,129
Joined: May 25 2013
Gold: 0.11
Oct 4 2013 10:21pm
"Write a program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:

a. Any call started between 8:00 A.M. and 5:00 P.M., inclusive, Monday through Friday, is billed at a rate of $0.50 per minute.
b. Any call started before 8:00 A.M. or after 5:00 P.M., Monday through Friday, is billed at a rate of $0.25 per minute.
c. Any call started on a Saturday or Sunday is billed at a rate of $0.10 per minute.

NOTE: Be very careful! A call started at 5:00pm exactly is billed at one rate. A call started at 5:01pm is billed at another rate!
The input will consist of the day of the week, the time the call started, and the length of the call in minutes. The output will be the cost of the call. The time is to be input in 24-hour notation, so the time 1:30 P.M. is input as:
13:30

The day of the week will be read as one of the following pairs of character values, which are stored in two variables of type char:
Mo Tu We Th Fr Sa Su

Be sure to allow the user to use either uppercase or lowercase letters or a combination of the two. The number of minutes will be input as a value of type int. (You can assume that the user rounds the input to a whole number of minutes.) Your program should include a loop that lets the user repeat this calculation until the user says she or he is done"


here's my code so far


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;



int main()
{

char dayF, dayS;
double timeofcall;
int lengthofcall;

while(true){

cout << " Enter the first two initials of the day the call was made \n ";
cin >> dayF >> dayS;

if(dayF == 'm' && dayS == 'o' || dayF == 't' && dayS == 'u' || dayF == 'w' && dayS == 'e' || dayF == 't' && dayS == 'r' || dayF == 'f' && dayS == 'r' || dayF == 's' && dayS == 'a' || dayF == 's' && dayS == 'u')
break;
if(dayF == 'M' && dayS == 'o' || dayF == 'T' && dayS == 'u' || dayF == 'W' && dayS == 'e' || dayF == 'T' && dayS == 'r' || dayF == 'F' && dayS == 'r' || dayF == 'S' && dayS == 'a' || dayF == 'S' && dayS == 'u')
break;
if(dayF == 'm' && dayS == 'O' || dayF == 't' && dayS == 'U' || dayF == 'w' && dayS == 'E' || dayF == 't' && dayS == 'R' || dayF == 'f' && dayS == 'R' || dayF == 's' && dayS == 'A' || dayF == 's' && dayS == 'U')
break;
}

cout << "In format hour - minute, enter the time of the call \n ";
cin >> timeofcall;

cout << "How long, in minutes, did the call last? \n";
cin >> lengthofcall;




return 0;
}


I know there are much better, more experienced c++ writers out there. I'm actually having fun trying to make this work, and I'm trying to make it as perfect as I can. However, any insight will be greatly appreciated.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 4 2013 10:27pm
Quote
int main()
{

char dayF, dayS;
double timeofcall;
int lengthofcall;

while(true){

cout << " Enter the first two initials of the day the call was made \n ";
cin >> dayF >> dayS;

if(dayF == 'm' && dayS == 'o' || dayF == 't' && dayS == 'u' || dayF == 'w' && dayS == 'e' || dayF == 't' && dayS == 'r' || dayF == 'f' && dayS == 'r' || dayF == 's' && dayS == 'a' || dayF == 's' && dayS == 'u')
break;
if(dayF == 'M' && dayS == 'o' || dayF == 'T' && dayS == 'u' || dayF == 'W' && dayS == 'e' || dayF == 'T' && dayS == 'r' || dayF == 'F' && dayS == 'r' || dayF == 'S' && dayS == 'a' || dayF == 'S' && dayS == 'u')
break;
if(dayF == 'm' && dayS == 'O' || dayF == 't' && dayS == 'U' || dayF == 'w' && dayS == 'E' || dayF == 't' && dayS == 'R' || dayF == 'f' && dayS == 'R' || dayF == 's' && dayS == 'A' || dayF == 's' && dayS == 'U')
break;
}


cout << "In format hour - minute, enter the time of the call \n ";
cin >> timeofcall;

cout << "How long, in minutes, did the call last? \n";
cin >> lengthofcall;




return 0;
}


i recommend you build subroutines to help you out. it'll split the logic into separate parts to make it easier to focus as well as debug. the highlighted code has no place in your main function for example. split that into a separate function.

as for the time itself, i recommend having a function split the duration into separate components, where each component has a single billing rate.

/edit: take back the last part. i thought the bill was going to be split, but it looks like it only depends on when the call started. so you should have a function that determines which of those 3 slots it fits into.

This post was edited by carteblanche on Oct 4 2013 10:28pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll