5 Replies - 385 Views - Last Post: 03 August 2014 - 04:08 AM Rate Topic: -----

#1 Naktah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-July 14

help with if statements..

Posted 31 July 2014 - 07:00 PM

can someone help me here? here is the program description:an ISP has 3 different packages for its customers:PackageA for 250.00 per month,10 hours of access is provided.additional hours are 150/hour.PackageB for 500/month,20 hours of access,additional hours is 10/hour.PackageC with 900/month,unlimited access is provided.
the conditions in the program are:

1.user only selects packages A,B,C.
2.month entered must be a valid month.
3number of hours must not exceed the total number of hours per month based on the data below:
months with 31 days-744 hours
months with 30 days-720 hours
months with 28 days-672 hours

this is the code i have been doing on so far

#include <iostream>
using namespace std;

int main ()
{

double packageA, packageB, packageC;
int input, hours, month;


packageA= 200.00;
packageB= 500.00;
packageC= 900.00;

cout<<"Enter package [A,B,C]: ";
cin>> input;

cout<<"\nEnter the month(in number): ";
cin>> month;

cout<<"\nEnter the number of hours used: ";
cin>> hours;

if (input == 'A' && hours<=10)
	cout<< "\nTotal amount due is: "<<packageA;
else if  (input == 'A' && hours > 10 && hours <=744)
	cout<< "\nTotal amount due is: "<<(packageA + (hours - 10) * 2);
else if (input == 'B' && hours <=20)
    cout<< "\nTotal amount due is: "<<packageB;
else if (input == 'B' && hours > 20 && hours <=720)
	cout<< "\nTotal amount due is: "<<((packageB) + (hours - 20) * 1);
else
	cout<< "\nTotal amount due is: "<<packageC;

return 0;
}
/*months with 31 days:1,3,5,7,8,10,12;hours max is 744
months with 30 days:4,6,9,11;hours max is 720
months with 28 days:2;hours max is 672
Package A: For Php200.00 per month, 10 hours of access are provided. Additional hours are Php15.00 per hour.
Package B: For Php500.00 per month, 20 hours of access are provided. Additional hours are Php10.00 per hour.
Package C: For Php900.00 per month, unlimited access is provided.*/


there are no errors when i compile it,but problem is i cant put an in put in the month and number of hours used! can someone help me?? and also how can i put the total number of hours per month as what the description says?? thank you very much.

Is This A Good Question/Topic? 0
  • +

Replies To: help with if statements..

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1675
  • View blog
  • Posts: 3,169
  • Joined: 30-May 10

Re: help with if statements..

Posted 31 July 2014 - 09:27 PM

08 int input, hours, month;
09
10
11 packageA= 200.00;
12 packageB= 500.00;
13 packageC= 900.00;
14
15 cout<<"Enter package [A,B,C]: ";
16 cin>> input;

A B C are not integers.
Was This Post Helpful? 1
  • +
  • -

#3 Naktah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-July 14

Re: help with if statements..

Posted 01 August 2014 - 03:45 AM

View PostSalem_c, on 31 July 2014 - 09:27 PM, said:

08 int input, hours, month;
09
10
11 packageA= 200.00;
12 packageB= 500.00;
13 packageC= 900.00;
14
15 cout<<"Enter package [A,B,C]: ";
16 cin>> input;

A B C are not integers.


oh yeah,almost forgot bout that.thanks.haha

but how can i put the conditions stated? should i include them inside the if statements?? im really confused.newbie at programming here
Was This Post Helpful? 0
  • +
  • -

#4 Naktah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-July 14

Re: help with if statements..

Posted 01 August 2014 - 04:14 AM

if (input == 'A' && hours<=10)
	cout<< "\nTotal amount due is: "<<packageA;
else if  (input == 'A' && hours > 10 && (hours <=744 && month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) || (hours <=720 && month == 4 || month == 6 || month == 9 || month == 11) || (hours <=672 && month == 1))
	cout<< "\nTotal amount due is: "<<(packageA + (hours - 10));
else if (input == 'B' && hours <=20)
    cout<< "\nTotal amount due is: "<<packageB;
else if (input == 'B' && hours > 20 && (hours <=744 && month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) || (hours <=720 && month == 4 || month == 6 || month == 9 || month == 11) || (hours <=672 && month == 1))
	cout<< "\nTotal amount due is: "<<((packageB) + (hours - 20));
else
	cout<< "\nTotal amount due is: "<<packageC;

return 0;
}
/*months with 31 days:1,3,5,7,8,10,12;hours max is 744
months with 30 days:4,6,9,11;hours max is 720
months with 28 days:2;hours max is 672
Package A: For Php200.00 per month, 10 hours of access are provided. Additional hours are Php15.00 per hour.
Package B: For Php500.00 per month, 20 hours of access are provided. Additional hours are Php10.00 per hour.
Package C: For Php900.00 per month, unlimited access is provided.*/


i tried doing this,but it seems pretty stupid though,and it inputs the wrong conditions..
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3569
  • View blog
  • Posts: 11,089
  • Joined: 05-May 12

Re: help with if statements..

Posted 01 August 2014 - 06:25 AM

Item #3 in the post is sort of a red herring. It's simply the number of hours in a day times the number of days in a month. Eg. 31 days * 24 hours/day == 744 hours. So all this means is that you'll need a lookup table to find the number of days in a month, and you can compute the maximum number of hours for that month.
Was This Post Helpful? 1
  • +
  • -

#6 Naktah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-July 14

Re: help with if statements..

Posted 03 August 2014 - 04:08 AM

so i would just ignore what item #3 says?

this is what i did in my code.i've changed a few. but i think this would work..
#include <iostream>
using namespace std;

int main ()
{

double packageA, packageB, packageC;
int hours, month;
char input;


packageA= 200.00;
packageB= 500.00;
packageC= 900.00;

cout<<"Enter package [A,B,C]: ";
cin>> input;
{
if(input == 'C' || input == 'c')
{
	cout<<"\nTotal amount due is: "<<packageC;
	return 0;
}
else
	cout<<"\nEnter the month(in number): ";
	cin>>month;

	cout<<"\nEnter the number of hours used: ";
	cin>>hours;
}

if (input == 'A' || input == 'a' && hours > 10)
	cout<< "\nTotal amount due is: "<<(packageA + (hours - 10) * 15);

else if (input == 'A' || input == 'a' && hours<=10)
	cout<< "\nTotal amount due is: "<<packageA;
else if (input == 'B' || input == 'b' && hours > 20)
	cout<< "\nTotal amount due is: "<<((packageB) + (hours - 20) * 10);
else if (input == 'B' || input == 'b' && hours <=20)
    cout<< "\nTotal amount due is: "<<packageB;
else
	cout<<" ";



return 0;
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1