using if else statements

homework problem i need done

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2748 Views - Last Post: 01 October 2010 - 12:32 PM Rate Topic: -----

#1 Guest_Mandi*


Reputation:

using if else statements

Posted 01 October 2010 - 09:56 AM

So I have a homework problem I have to get done..its three parts. I know I can't go on until I figure out the first...I have to create a program that calculates a customers monthly bill for internet service providing.

package a= 9.95 a month per 10 hours of access. additional hours are 2.00.
package b= 14.95 a month per 20 hours of access. additional hours are 1.00.
package c= 19.95 a month for unlimited access..

i have to ask what package the customer is using and how many hours were used. then it displays the total amount due.

this is what i have so far..

#include <iostream>
using namespace std;

int main ()
{

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


packageA= 9.95;
packageB= 14.95;
packageC= 19.95;

cout<<"What package did you choose? Choose either A, B, or C.";
cin>> input;

	if (input == 'A')
		cout<<"You purchased package A.";
	else if (input == 'B')
	    cout<<"You purchased package B.";
	else if (input == 'C')
	    cout<< "You purchased package C.";

cout<<"How many hours were used?";
cin>> hours;

if (input == 'A' && hours<=10)
	cout<< "Your total is 10.95.";
else if  (input == 'A' && hours > 10)
	cout<< "Your total is"  + (packageA + (hours - 10) * 2);
else if (input == 'B' && hours <=20)
    cout<< "Your total is 14.95.";
else if (input == 'B' && hours > 20)
	cout<< "Your total is" + (packageB) + (hours - 20) * 1);
else if (input =='C')
	cout<< "Your total is 19.95.";


}




help? lol
can someone edit it for me so i can see what ive done wrong?

Is This A Good Question/Topic? 0

Replies To: using if else statements

#2 aaa111  Icon User is offline

  • D.I.C Regular

Reputation: 88
  • View blog
  • Posts: 284
  • Joined: 21-February 07

Re: using if else statements

Posted 01 October 2010 - 10:11 AM

Look at this:
int input

and this:
cin>> input;

	if (input == 'A')
		cout<<"You purchased package A.";
	else if (input == 'B')
	    cout<<"You purchased package B.";
	else if (input == 'C')
	    cout<< "You purchased package C.";


Here input should be char type.
Also what is this:
cout<< "Your total is"  + (packageA + (hours - 10) * 2);


Is'nt it should be like this:
cout<< "Your total is" << (packageA + (hours - 10) * 2);

Same goes for the next cout in your program.

And most importantly exit your program with
return 0;

This post has been edited by aaa111: 01 October 2010 - 10:21 AM

Was This Post Helpful? 1
  • +
  • -

#3 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: using if else statements

Posted 01 October 2010 - 10:16 AM

well start with telling us what is happening instead of just saying it is wrong. on a second note, you will want to use a switch case for choosing which package they want. as for you output use a switch case as well and brake it down to 'A', 'B', 'C' then use a single mathematical formula and output that, these are just suggestions however.

edit:

Quote

Is'nt it should be like this:
view source
print?
out<< "Your total is" << (packageA + (hours - 10) * 2);


what are you talking about, cout is a out put stream to stdout so yes cout is correct not out.

This post has been edited by ishkabible: 01 October 2010 - 10:19 AM

Was This Post Helpful? 1
  • +
  • -

#4 Guest_Mandi*


Reputation:

Re: using if else statements

Posted 01 October 2010 - 10:19 AM

That stuff you posted at the bottom was me trying to get the total if the hours are greate than a certain amount.



View Postaaa111, on 01 October 2010 - 09:11 AM, said:

Look at this:
int input

and this:
cin>> input;

	if (input == 'A')
		cout<<"You purchased package A.";
	else if (input == 'B')
	    cout<<"You purchased package B.";
	else if (input == 'C')
	    cout<< "You purchased package C.";


Here input should be char type.
Also what is this:
cout<< "Your total is"  + (packageA + (hours - 10) * 2);


Is'nt it should be like this:
out<< "Your total is" << (packageA + (hours - 10) * 2);

Same goes for the next cout in your program.

And most importantly exit your program with
return 0;

Was This Post Helpful? 1

#5 aaa111  Icon User is offline

  • D.I.C Regular

Reputation: 88
  • View blog
  • Posts: 284
  • Joined: 21-February 07

Re: using if else statements

Posted 01 October 2010 - 10:22 AM

View Postishkabible, on 01 October 2010 - 09:16 AM, said:

what are you talking about, cout is a out put stream to stdout so yes cout is correct not out.

I am sorry it was a typo.I edited it properly.
Was This Post Helpful? 0
  • +
  • -

#6 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: using if else statements

Posted 01 October 2010 - 10:26 AM

the extra if statements and conditional are pointless just use packageX+OverRate(hours-MaxHours) will work just fine for all of them.
Was This Post Helpful? 0
  • +
  • -

#7 aaa111  Icon User is offline

  • D.I.C Regular

Reputation: 88
  • View blog
  • Posts: 284
  • Joined: 21-February 07

Re: using if else statements

Posted 01 October 2010 - 10:27 AM

View PostMandi, on 01 October 2010 - 09:19 AM, said:

That stuff you posted at the bottom was me trying to get the total if the hours are greate than a certain amount.


Well the use of + operator before the (packageA + (hours - 10) * 2) was wrong,if you want to send something into the stream you have to use <<.So,replace that + with <<.
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Mandi*


Reputation:

Re: using if else statements

Posted 01 October 2010 - 10:42 AM

What does it mean when you debug something and it says unresolved external?? My program won't run. lol
Was This Post Helpful? 0

#9 Guest_Samantha*


Reputation:

Re: using if else statements

Posted 01 October 2010 - 11:16 AM

I have to create a program that calculates a customers monthly bill for internet service providing.

package a= 9.95 a month per 10 hours of access. additional hours are 2.00.
package b= 14.95 a month per 20 hours of access. additional hours are 1.00.
package c= 19.95 a month for unlimited access..

i have to ask what package the customer is using and how many hours were used. then it displays the total amount due.

i got that part finished. now i have to somehow dispplay how much money package A customers would save if they purchased B or C. And how much money Package B customers would save if they purchased Package C. If theres no savings, no message is displayed.

so how exactly do you incorporate that into your program without screwing everything else up?
Was This Post Helpful? 0

#10 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: using if else statements

Posted 01 October 2010 - 11:48 AM

either you just another thread on the same thing or you are in the same class as someone else that already posted in this class. my guess is your the same person as the text is exactly the same, so go back and ask this question in the forum you started the topic in.
Was This Post Helpful? 0
  • +
  • -

#11 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: using if else statements

Posted 01 October 2010 - 11:53 AM

post code and full error then we can help
Was This Post Helpful? 0
  • +
  • -

#12 Guest_Mandi*


Reputation:

Re: using if else statements

Posted 01 October 2010 - 12:05 PM

heres what i have:

#include <iostream>
using namespace std;

int main ()
{

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


packageA= 9.95;
packageB= 14.95;
packageC= 19.95;

hours <= 744;

cout<<"What package did you choose? Choose either A, B, or C.";
cin>> input;

	if (input == 'A')
		cout<<"You purchased package A.";
	else if (input == 'B')
	    cout<<"You purchased package B.";
	else if (input == 'C')
	    cout<< "You purchased package C.";
	else
		cout<<" You did not enter A, B, or C.";

cout<<"How many hours were used?";
cin>> hours;

if (input == 'A' && hours<=10)
	cout<< "Your total is" << packageA;
else if  (input == 'A' && hours > 10)
	cout<< "Your total is"  << (packageA + (hours - 10) * 2);
else if (input == 'B' && hours <=20)
    cout<< "Your total is" << packageB;
else if (input == 'B' && hours > 20)
	cout<< "Your total is"  << (packageB + (hours - 20) * 1);
else if (input =='C')
	cout<< "Your total is " << packageC;

   return 0;

}





and it comes up with:

1>------ Build started: Project: ISPProvider, Configuration: Debug Win32 ------
1>Build started 10/1/2010 3:05:14 PM.
1>InitializeBuildStatus:
1> Touching "Debug\ISPProvider.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\users\mandi\documents\visual studio 2010\Projects\ISPProvider\Debug\ISPProvider.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.35
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


View Postishkabible, on 01 October 2010 - 10:53 AM, said:

post code and full error then we can help

Was This Post Helpful? 0

#13 aaa111  Icon User is offline

  • D.I.C Regular

Reputation: 88
  • View blog
  • Posts: 284
  • Joined: 21-February 07

Re: using if else statements

Posted 01 October 2010 - 12:11 PM

What's the point of this:
hours <= 744;

This post has been edited by aaa111: 01 October 2010 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#14 Guest_Mandi*


Reputation:

Re: using if else statements

Posted 01 October 2010 - 12:23 PM

Well it said the hours have to be less than or equal to 744. i wasnt sure where to put that in the code.
Was This Post Helpful? 0

#15 aaa111  Icon User is offline

  • D.I.C Regular

Reputation: 88
  • View blog
  • Posts: 284
  • Joined: 21-February 07

Re: using if else statements

Posted 01 October 2010 - 12:28 PM

hours <= 744 is a conditional expression,they should be used with conditional statement like if,for or while.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2