# Thread: if... else statement errors?

1. ## if... else statement errors?

I'm having a bit of trouble with the if... else statements. I thought I had it right, but when I start the program... I don't get any results. I'll post the problem and my code and maybe someone could help me out.

Problem:
CSC110
IF…ELSE Program

Description: The new Telephone Company has the following rate structure for long-distance calls:

1. The regular rate for a call is \$0.10 per minute
2. Any call started at or after 6:00pm (1800 hours) but before 8:00 am is discounted 50%
3. Any call longer than 60 minutes receives a 15% discount on its cost (after any other discount is subtracted).
4. All calls are subject to a 4% federal tax on their final cost.

Write a program that reads the start time for a call based on a 24-hour clock and the length of the call. Your report should show the gross cost (before any discounts or tax) , the disount (even if it is 0), the tax, and finally the net cost (after discounts are deducted and tax is added).

Code:
```#include <iostream>
#include <iomanip>

using namespace std;

int main()

{
// local variable
int Start_Time;
int Length_First;
int Length_Second;
int Length_Third;
int End_Time;
float Total;
float Gross_Cost; //for gross cost
float Length_Discount; //for length discount
float Time_Discount; //for time discount
float Total_Discounts; //for total discounts
float Tax; //for tax
float Reg_Rate = .10;

// local constants
const int FULL_MIN = 60;
const int SIX_PM = 1800;
const int EIGHT_AM = 800;
const int OVER_HOUR = 0060;

// Input Time Of Call
cout << "What was the time of your phone call?";
cin  >> Start_Time;

// Input Length Of Minutes
cout << "What was the length of your phone call in minutes?";
cin  >> Length_First;

//Clear the screen
system("cls");

//Calculate Discount
Total_Discounts = Length_Discount + Time_Discount;

//Calculate Total
Total = Gross_Cost - Total_Discounts;

//Calculate Tax
Tax = Total * 1.1;

//If Statement

if(Length_First >= FULL_MIN) //changes length if over 60 min.
Length_Second = Length_First % FULL_MIN; //modulus by 60
{
End_Time = Length_Third + Start_Time; //calculates total

else if(Length_Third > OVER_HOUR) //starts if length is over 0060
Length_Discount = Gross_Cost * 0.2; //calculates length discounts

else if(SIX_PM >= Length_Third || Length_Third >= EIGHT_AM)
Time_Discount = Gross_Cost * 0.5; //calculates time discounts
}
// End If

//Display the percent of each model sold
cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);
cout << "\n\n\n\n\n\n\n\n";
cout << setw(56) << "Telephone Bill             "  << "\n";
cout << setw(43) << "Category        " << setw(9)  << "Total"            << "\n\n";
cout << setw(43) << "Original Gross  " << setw(9)    << Gross_Cost        << endl
<< setw(43) << "Discount        " << setw(9)    << Total_Discounts     << endl
<< setw(43) << "Tax             " << setw(9)  <<  Tax               << endl
<< setw(43) << "Final Gross     " << setw(9)  <<  Total
<< "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

//Pause The Output Screen For Viewing
system("pause");

return 0;

} // End Of Program```

2. After the beginning of the first if-statement(Changes length if over 60 minutes), shouldn't the assignment be inside the brackets? Also, in the next if-statement(Add 100) you have an assignment instead of a comparison, consider if that's really what you want. Additionally, use the compiler warnings, you are using some uninitialized variables in your calculations, namely:

Length_Discount
Time_Discount
Gross_Cost

Not sure if that's everything. Maybe state what the actual problem is?

3. Code:
```if(Length_Third = Length_Second + ADD_HUNDRED) //adds 100
End_Time = Length_Third + Start_Time; //calculates total```

That's your first problem. You used an assignment operator so no matter what tests you do your Length_Third variable will always equal (Length_Second + ADD_HUNDRED). Use the '==' operator instead.

Code:
```    if(Length_First >= FULL_MIN) //changes length if over 60 min.
Length_Second = Length_First % FULL_MIN; //modulus by 60
{