Output is not same of program

I am facing a little bit problem with the output of program. Where I am making mistake?, I don't know.

Problem is:

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:

1. Any call started between 8:00AM and 6:00PM, Monday through Friday, is billed at the rate of $0.40 per minute.

2. Any call starting before 8:00AM or after 6:00PM, Monday through Friday, is charged at the rate of $0.25 per minute.

3. Any call started on a Saturday or Sunday is charged at the rate of $0.15 per minute.

In your program, you will ask the user to provide input for three things: (1) The day of week, (2) The time the call started and (3) The length of the call in minutes. Output is the cost of the call. The time is to be input in 24-hour notation, so 1:30 PM is input as 13:30.

The day of week will be read as a pair of character values (type char): Mo Tu We Th Fr Sa Su. You should allow the user to use either uppercase or lowercase letters.

Here What I am doing:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <string>
using namespace std;
int main()
{
	int start_hour, length_hour, length_min;
	double cost;
	string day;
	char wheel;

	do
	{
		cout << "Lets calaulate the cost of your call" << endl;
		cout << "\n";

		cout << "On which day of week you have made call [Mo or Fr]: ";
		cin >> day;

		cout << "On which hour you started your call [24 hours]: ";
		cin >> start_hour;

		cout << "Enter the length of your call now, first enter hour:\n";
		cout << "If call is less than hour then enter hour as ZERO\n";
		cin >> length_hour;
		cout << "Now enter minutes of your call: ";
		cin >> length_min;


		if (day == "mo" || day == "Mo" || day == "tu" || day == "Tu" || day == "we" || day == "We" || day == "th" || day == "Th" || day == "fr" || day == "Fr")
		{
			if (start_hour > 0)
			{
				start_hour *= 60;
				length_min += start_hour;
			}
			else
			{
				length_min += start_hour;
			}

			if (start_hour >= 8 && start_hour <= 18)
			{
				cost = length_min * 0.40;
			}
			else
			{
				cost = length_min * 0.25;
			}
		}
		else if (day == "Sa" || day == "sa" || day == "Su" || day == "su")
		{
			if (start_hour > 0)
			{
				start_hour *= 60;
				length_min += start_hour;

			}
			else
			{
				length_min += start_hour;
			}

			cost = length_min * 0.15;
		}

		cout << endl << "Your cost of this call is: $" << cost << endl;

		cout << "Do you want to use this software again?\n";
		cout << "Type y for Yes and n for No\n";
		cin >> wheel;
	} while (wheel == 'y' || wheel == 'Y');

	cout << "\n";
	system("pause");

	return 0;
}


Output is not accurate, for example I select Mo as day, 9 as the hour when I started call, and length of my call was 1:02 (62 mins) so the output should be 24.8 but it is giving 216.8. Why?
Last edited on
Problem solved.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int start_hour, length_hour, length_min;
	double cost;
	string day;
	char wheel;

	do
	{
		cout << "Lets calaulate the cost of your call" << endl;
		cout << "\n";

		cout << "On which day of week you have made call [Mo or Fr]: ";
		cin >> day;

		cout << "On which hour you started your call [24 hours]: ";
		cin >> start_hour;

		cout << "Enter the length of your call now, first enter hour:\n";
		cout << "If call is less than hour then enter hour as ZERO\n";
		cin >> length_hour;
		cout << "Now enter minutes of your call: ";
		cin >> length_min;


		if (day == "mo" || day == "Mo" || day == "tu" || day == "Tu" || day == "we" || day == "We" || day == "th" || day == "Th" || day == "fr" || day == "Fr")
		{
			if (length_hour > 0)
			{
				length_hour *= 60;
				length_min += length_hour;
			}
			else
			{
				length_min += length_hour;
			}

			if (start_hour >= 8 && start_hour <= 18)
			{
				cost = length_min * 0.40;
			}
			else
			{
				cost = length_min * 0.25;
			}
		}
		else if (day == "Sa" || day == "sa" || day == "Su" || day == "su")
		{
			if (length_hour > 0)
			{
				length_hour *= 60;
				length_min += length_hour;

			}
			else
			{
				length_min += length_hour;
			}

			cost = length_min * 0.15;
		}

		cout << endl << "Your cost of this call is: $" << cost << endl;

		cout << "Do you want to use this software again?\n";
		cout << "Type y for Yes and n for No\n";
		cin >> wheel;
	} while (wheel == 'y' || wheel == 'Y');

	cout << "\n";
	system("pause");

	return 0;
}
Last edited on
Topic archived. No new replies allowed.