please help me - extremely clueless :(

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2004
Posts: 26
Reputation: dello is an unknown quantity at this point 
Solved Threads: 0
dello dello is offline Offline
Light Poster

please help me - extremely clueless :(

 
0
  #1
Dec 13th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 26
Reputation: dello is an unknown quantity at this point 
Solved Threads: 0
dello dello is offline Offline
Light Poster

Re: please help me - extremely clueless :(

 
0
  #2
Dec 13th, 2004
this is what i have so far

  1. #include <stdio.h>
  2.  
  3. const float hi_rate=1.50;
  4. const float norm_rate=0.30;
  5. const float max_dur=600;
  6.  
  7. char day;
  8. int st_hr, end_hr, st_min, end_min, call_dur, total_calls, total_dur;
  9. float call_cost, total_cost;
  10.  
  11. main()
  12. {
  13. /* printf("\n\t\tDay of call: ");
  14.   scanf("%",&day);*/
  15. printf("\n\t\tEnter Call Start Hour: ");
  16. scanf("%d",&st_hr);
  17. printf("\n\t\tEnter Call Start Minute: ");
  18. scanf("%d",&st_min);
  19. printf("\n\t\tEnter Call End Hour: ");
  20. scanf("%d",&end_hr);
  21. printf("\n\t\tEnter Call End Minute: ");
  22. scanf("%d",&end_min);
  23. getchar();
  24.  
  25. call_dur=(end_hr - st_hr)*60 + end_min-st_min;
  26. if (call_dur < max_dur)
  27. {
  28. /*printf("\n\t\tday was: % ",day);*/
  29. printf("\n\t\tDuration of call was %d minutes ",call_dur);
  30. printf("\n\t\tCost of call was %d ",call_cost);
  31. }
  32. else
  33. printf("\n\t\tCall time exceeded");
  34.  
  35.  
  36. getchar();
  37. }

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..
Last edited by alc6379; Dec 13th, 2004 at 7:35 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: please help me - extremely clueless :(

 
0
  #3
Dec 13th, 2004
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 26
Reputation: dello is an unknown quantity at this point 
Solved Threads: 0
dello dello is offline Offline
Light Poster

Re: please help me - extremely clueless :(

 
0
  #4
Dec 13th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: please help me - extremely clueless :(

 
0
  #5
Dec 13th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 26
Reputation: dello is an unknown quantity at this point 
Solved Threads: 0
dello dello is offline Offline
Light Poster

Re: please help me - extremely clueless :(

 
0
  #6
Dec 13th, 2004
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
  1. #include <stdio.h>
  2. main()
  3. {
  4. int i;
  5. printf("Enter a day ");
  6. scanf("%d",&i);
  7.  
  8. switch (i)
  9. {
  10. case 1:
  11. printf("Monday");
  12. break;
  13. case 2:
  14. printf("Tuesday");
  15. break;
  16. case 3:
  17. printf("Wednesday");
  18. break;
  19. case 4:
  20. printf("Thursday");
  21. break;
  22. case 5:
  23. printf("Friday");
  24. break;
  25. case 6:
  26. printf("Saturday");
  27. break;
  28. case 7:
  29. printf("Sunday");
  30. break;
  31.  
  32. default:
  33. printf("Day Not Recognised");
  34. getchar();
  35. }
  36. getchar();
  37. getchar();
  38. }

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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 26
Reputation: dello is an unknown quantity at this point 
Solved Threads: 0
dello dello is offline Offline
Light Poster

Re: please help me - extremely clueless :(

 
0
  #7
Dec 13th, 2004
please? anyone??
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: please help me - extremely clueless :(

 
0
  #8
Dec 13th, 2004
Originally Posted by dello
please? anyone??
Yes, sure...Your code works on my compiler; except you should use int main () . What kind of errors dou you get?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 26
Reputation: dello is an unknown quantity at this point 
Solved Threads: 0
dello dello is offline Offline
Light Poster

Re: please help me - extremely clueless :(

 
0
  #9
Dec 13th, 2004
Originally Posted by frrossk
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)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: please help me - extremely clueless :(

 
0
  #10
Dec 13th, 2004
  1. char i;
  2. //...
  3. scanf("%c", &i);
  4. //...
  5. case 'w':
  6. case 'W':
  7. printf("Wednesday");
  8. break;
  9. //...

Good enough?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC