Grrl in limbo c++ using if, if else and switchs.

• 03-23-2011
Miseri
Grrl in limbo c++ using if, if else and switchs.
Code:

``` //Design a C++ program that asks the user to enter the number of pages to be faxed? //The algorithm then uses the number of pages to be faxed to the calculate the amount //due. #include <iostream> using namespace std; int main() {         double billingAmount;         double numOfPages;                 cout << "Enter number of pages to faxed: ";         cin  >> numOfPages;                         if (numOfPages <= 10)                 cout << "Billing Amount for less than 10 pages: " << endl;                 cin >> billingAmount >>                 cout << "Bill Amount: " << endl;         else (numOfPages > 10)         cout << "bill amount for more than 10 pages: " << billingAmount << "Bill Amount: " << endl;                 billingAmount = 3.00 + (numOfPages * 0.20);                           billingAmount = 3.00 + 10 * 0.20+(numOfPages - 10) * 0.10;                                                 return 0; } This is what I have and its probably wrong. This is the information I'm trying to go by. numOfPages = # of pages to be faxed billingAmount = total charges for the pages faxed. numOfPages is less than or equal to 10 the billing amount is serivce charges + (numOfPages x 0.20); otherwise, billing amount is service charges + 10 X 0.20 + (numOfPages - 10) x .10. Get numOfPages calculate billing amount using the formula: if (numOfPages is less than or equal to 10) billingAmount = 3.00 + (numOfPages X 0.20); else if billingAmount-3.00+10x0.20+(numOfPage… = 10) x 0.10;```
• 03-23-2011
itsme86
Code:

```        if (numOfPages <= 10)                 cout << "Billing Amount for less than 10 pages: " << endl;                 cin >> billingAmount >>                 cout << "Bill Amount: " << endl;         else (numOfPages > 10)         cout << "bill amount for more than 10 pages: " << billingAmount << "Bill Amount: " << endl;                 billingAmount = 3.00 + (numOfPages * 0.20);                           billingAmount = 3.00 + 10 * 0.20+(numOfPages - 10) * 0.10;```
You don't need to get the billingAmount from the user. You're just supposed to calculate it based on the number of the pages. Also, you don't need a condition for the else:
Code:

```  if (numOfPages <= 10)     billingAmount = 3.00 + (numOfPages * 0.20);   else     billingAmount = 3.00 + 10 * 0.20+(numOfPages - 10) * 0.10;```
You had all the code there, you just had a whole lot of extra. ;)
• 03-23-2011
Miseri
Thanks for the help Itsme86 and it executes the program but it doesn't perform the calculations when I input a number and the program closes.

Code:

```if (numOfPages <= 10)                 billingAmount = 3.00 + (numOfPages * 0.20);         else       billingAmount = 3.00 + 10 * 0.20+(numOfPages - 10) * 0.10;                 return 0; }```
Thanks for all the help.
• 03-23-2011
itsme86
Then print it out before the return statement: cout << "Billing amount: " << billingAmount;