hi all, i need urgent help. i am currently learning c++ and i have been given a program to write, I am really struggling with it and as it is an assignment whic needs to be handed in tomorrow i really need help :( - im not lazy its just that im not grasping the concept very well at the moment and my tutor is too damn strict, wont give me help directley related to the assignment, can someone please help me out - below is the problem in detail. i am using the bloodshed compiler - http://www.bloodshed.net

I have to write a program that calculates charges for long-distance telephone calls according to the following scheme:

The regular charge rate is £1.50 for the first three minutes (or part thereof) and 30 pence for any minute after the first three. Rates are reduced during certain times of the day according to the following:

Monday to Friday
Before 8 a.m - 40% discount
8.am to 6pm (inclusive - regular rate)
after 6 pm - 40% discount

Saturday and Sunday
60% discount applies

the input to the program is to consist of the day on which the call was begun, the starting time of the call and the end time of the call. No call is to be greater than ten hours in duration.

the day is to be indicated by using a key letter: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.

the times are to be entered to the nearest minute using 24 hour clock format. each time should consist of two parts - hours and minutes. midnight is 00 hours and 00 minutes. 1.35 pm is represented as 13 hours and 35 minutes.

the program is to display the day of the week as a full name, the call duration in minutes and the total charge.

The program should execute in a loop and so consideration must be given to how the processing requirements are to end.

complete the program by including a summary analysis which will determine the total number of calls made, the total duration of the calls and the total cost of all the calls made

many thanks in advance

Recommended Answers

All 10 Replies

this is what i have so far

#include <stdio.h>

const float hi_rate=1.50;
const float norm_rate=0.30;
const float max_dur=600;

char day;
int st_hr, end_hr, st_min, end_min, call_dur, total_calls, total_dur;
float call_cost, total_cost;

    /* printf("\n\t\tDay of call:   ");
    printf("\n\t\tEnter Call Start Hour:   ");
    printf("\n\t\tEnter Call Start Minute:   ");
    printf("\n\t\tEnter Call End Hour:   ");
    printf("\n\t\tEnter Call End Minute:   ");

    call_dur=(end_hr - st_hr)*60 + end_min-st_min;
    if (call_dur < max_dur)
    /*printf("\n\t\tday was: %   ",day);*/
    printf("\n\t\tDuration of call was %d minutes  ",call_dur);
    printf("\n\t\tCost of call was %d ",call_cost);
  printf("\n\t\tCall time exceeded");    


I have the validation working so that it does not allow any calls to be more than 10 hours (600 minutes) long. But now i need to start using do while and nested if loops and i havn't got a clue where to start, if someone has a similar problem or examples of code - doesnt have to be this question specific, i can still work from that - i just don't know how to write from scratch..

please help..

thanks for that jwenting, i have had a look at the announcment - and have posted what i have so far - i am trying.. honestly! it's just that i can't seem do this on my own - im not asking anyone to write me the program, i just need a helping hand

I posted that link at the same time you were posting your code it seems...

What's so hard about using loops and conditionals?
Your courseware should have ample examples about them, and so does any programming book.

well - i just need help in knowing how to structure them, i mean i think i have understood the problem but just cannot seem to put it in code correctly - there is lots of validation that needs to be done and i cant figure how/where it should go.

for example - when entering a day, you only enter one letter but the output must be the full day name - i have no idea how to do this, there is sumthing i have found which is using the SWITCH statement, but i can't get it to work

#include <stdio.h>
 int i;
  printf("Enter a day  ");

  switch (i)
     case 1: 
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
     case 7:

      printf("Day Not Recognised");

like that piece of code will do what i want.. with the exception that i cannot enter a letter, i need to enter either 1-7 to display what i need - is there a better way of doing this using if statements? i dont know :confused:

please? anyone?? :(

please? anyone?? :(

Yes, sure...Your code works on my compiler; except you should use int main () . What kind of errors dou you get?

Yes, sure...Your code works on my compiler; except you should use int main () . What kind of errors dou you get?

Yeah, i mean the code works fine as it is.. but it doesn't quite work in the way i want it to.

I need to enter a single letter to display a day name .. ie

M= monday
U= tuesday
W= wednesday
T= thursday
F= friday
A= saturday
S= sunday

the switch i have got is fine, but it doesn't allow me to enter a character to display the name, it only allows me to use numbers 1-7 (which are the cases) I don't know if switch will accept characters in the case identifier as i cannot get it to work, i was wondering if there is any other way of doing what i want - ie - displaying a full day name from a single keystroke.. (make any sense)

char i;
scanf("%c", &i);
case 'w':
case 'W':

Good enough?

thank you, yes i have got that part of my program working fine now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.