Problems with logic

closed account (SNbpX9L8)
how would i put the savings if the person picks package(1) to how much they would have saved if they had picked package(2)..

heres my code..

#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;

int main () {

int pause;
int package;
int hours;
int savings;
double amountdue;
const double package_1= 9.95, package_2= 14.95, package_3=19.95;
string Fname;
string Lname;

cout << "Please enter both your first and last name: \n" << endl;
cin >> Fname;
cin >> Lname;

cout << "Please type 1, 2, or 3 for the internet package you purchased?: \n" << endl;
cout << " " << "Package(1)\n";
cout << " " << "Package(2)\n";
cout << " " << "Package(3)\n";
cin >> package;

cout << "Please enter how many hours did you use for this month?\n" << endl;
cin >> hours;



if (package==1)

{
if (hours >= 1 && hours <= 10)
{

cout << "Customer Name: " << Fname << " " << Lname;
cout << "\nPackage Purchased: " << package;
cout << "\nHours Used: " << hours;
cout << " \nThe total amount due is $" << package_1;

}
if (hours >=10 && hours <=744)
{
amountdue = package_1 + ((hours-10) * 2.0);
cout << "Customer Name: " << Fname << " " << Lname;
cout << "\nPackage Purchased: " << package;
cout << "\nHours Used: " << hours;
cout << " \nThe total amount due is $" << amountdue;
}


}


else if (package==2)

{

if (hours > 0 && hours <= 20)
{

cout << "Customer Name: " << Fname << " " << Lname;
cout << "\nPackage Purchased: " << package;
cout << "\nHours Used: " << hours;
cout << " \nThe total amount due is $" << package_2;
}
if (hours >= 20 && hours <= 744)
{
amountdue=package_2+((hours-20)*1.0);
cout << "Customer Name: " << Fname << " " << Lname;
cout << "\nPackage Purchased: " << package;
cout << "\nHours Used: " << hours;
cout << " \nThe total amount due is $" << amountdue;
}

}


else if (package==3)
{
if (hours > 20 && hours < 744)
{

cout << "Customer Name: " << Fname << " " << Lname;
cout << "\nPackage Purchased: " << package;
cout << "\nYour hours are unlimited ";
cout << " \nThe total amount due is $" << package_3;
}


}

if (package <=0 || package >=4)
{
cout << " That is an invalid package choice!";
}

if (hours <= 0 || hours >=744)
{
cout << "That is an invalid hours choice!";
}

cin >> pause;
return 0;
}
Hi,crawfoosh
In ur programme,there 5
cout << "Customer Name: " << Fname << " " << Lname;
cout << "\nPackage Purchased: " << package;
cout << "\nHours Used: " << hours;
cout << " \nThe total amount due is $" << package_1;


If inist on finishing ur logic use ur programm that will be a hard work.
some advice to You:

1,define a function only to count how much with given package and hours
2,call the function above,you can count out how much each of the package
will cost ,then compare them!

there is a example for step 1:
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
double cost(int package,int hours)
{
	double result=0;

	if(package == 1)
	{
		if (hours >= 1 && hours <= 10)
		{
			result = package_1;
		}
		if (hours >=10 && hours <=744)
		{
			result = package_1 + ((hours-10) * 2.0);
		}
		
		return result;
	}
	else if(package == 2)
	{
		if (hours >= 1 && hours <= 20)
		{
			result = package_2;
		}
		if (hours >=20 && hours <=744)
		{
			result = package_2 + ((hours-10) * 2.0);
		}
		
		return result;
	}
	else if(package == 3)
                   //ur package have some problem
                   //in ur programm,what will happen if hours < 20
	{
		if (hours >= 1 && hours <= 10)
		{
			result = package_3;
		}
		if (hours >=30 && hours <=744)
		{
			result = package_3 + ((hours-10) * 2.0);
		}
		
		return result;
	}
}


based on ur programm,I have finished a workable program:
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;

void print_result(int packagee,int hours);
double cost(int package,int hours);

const double package_1= 9.95, package_2= 14.95, package_3=19.95;
string Fname;
string Lname;

int main () 
{
	int pause;
	int package;
	int hours;
	//int savings;
	//double amountdue;

	cout << "Please enter both your first and last name: \n" << endl;
	cin >> Fname;
	cin >> Lname;

	cout << "Please type 1, 2, or 3 for the internet package you purchased?: \n" << endl; 
	cout << " " << "Package(1)\n";
	cout << " " << "Package(2)\n";
	cout << " " << "Package(3)\n";
	cin >> package; 

	cout << "Please enter how many hours did you use for this month?\n" << endl;
	cin >> hours;

	if (package <=0 || package >=4)
	{
		cout << " That is an invalid package choice!";
	}

	if (hours <= 0 || hours >=744)
	{ 
		cout << "That is an invalid hours choice!";
	}

//Above ,U got all the info of the user,
////////////////////////////////////////////////////////////////////
//next,u want to print the info,so use the function i wrapd for u,used ur idea! 

	print_result(package,hours);

	cin >> pause;
	return 0;
}
////////////////////////////////////////////////////////////////////////////
//use this functont to count how much he or she must pay in given package and hours
//U can use this function to count if the user use the other two packages also
//then,we do a compare,if there is a saving
////////////////////////////////////////////////////////////////////////////

double cost(int package,int hours)
{
	double result=0;

	if(package == 1)
	{
		if (hours >= 1 && hours <= 10)
		{
			result = package_1;
		}
		if (hours >=10 && hours <=744)
		{
			result = package_1 + ((hours-10) * 2.0);
		}
		
		return result;
	}
	else if(package == 2)
	{
		if (hours >= 1 && hours <= 20)
		{
			result = package_2;
		}
		if (hours >=20 && hours <=744)
		{
			result = package_2 + ((hours-10) * 2.0);
		}
		
		return result;
	}
	else //if(package == 3)
	{
		if (hours >= 1 && hours <= 10)
		{
			result = package_3;
		}
		if (hours >=30 && hours <=744)
		{
			result = package_3 + ((hours-10) * 2.0);
		}
		
		return result;
	}
}

///////////////////////////////////////////////////////////
//
//void print_result(int,int),need package and hours 
//like the name,it's call function cost to finish the tasks;
//
////////////////////////////////////////////////////////////
void print_result(int package,int hours)
{
		cout << "Customer Name: " << Fname << " " << Lname;
		cout << "\nPackage Purchased: " << package;
		cout << "\nHours Used: " << hours;
		cout << " \nThe total amount due is $" << cost(package,hours) <<endl;//use function "cost",to count out the costs 
		for(int ways=1;ways<=3;ways++)
		{
			if(ways != package && cost(ways,hours) < cost(package,hours))
				cout <<"\nIf u use pacakge "<< ways << " will save u $" << cost(package,hours)-cost(ways,hours) <<endl;
		}
}


cheers up`
Topic archived. No new replies allowed.