• (2 Pages)
• 1
• 2

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

}

```

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

• D.I.C Regular

Reputation: 88
• 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

### #3 ishkabible

• spelling expret

Reputation: 1669
• Posts: 5,817
• 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

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.

aaa111, 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;
```

### #5 aaa111

• D.I.C Regular

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

## Re: using if else statements

Posted 01 October 2010 - 10:22 AM

ishkabible, 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.

### #6 ishkabible

• spelling expret

Reputation: 1669
• Posts: 5,817
• 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.

### #7 aaa111

• D.I.C Regular

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

## Re: using if else statements

Posted 01 October 2010 - 10:27 AM

Mandi, 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 <<.

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

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?

### #10 ishkabible

• spelling expret

Reputation: 1669
• Posts: 5,817
• 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.

### #11 ishkabible

• spelling expret

Reputation: 1669
• Posts: 5,817
• 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

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 ==========

ishkabible, on 01 October 2010 - 10:53 AM, said:

post code and full error then we can help

### #13 aaa111

• D.I.C Regular

Reputation: 88
• 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

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.

### #15 aaa111

• D.I.C Regular

Reputation: 88
• 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.