jeudi 27 septembre 2018

Nested if else statements c++

Hey guys so Ive got this assignment Im working on that im having trouble with. I had to call everything that is an integer as part of the requirement so thats why only 59 and 60 is still a number.

My question is what am I missing to make this work? The only sample output Ive been able to make work is the first one.

Sample output 1:

Enter start time: 2322
Enter length of call in minutes: 67    
gross cost: $26.80
net cost: $11.85

Sample output 2:

Enter start time: 759
Enter length of call in minutes: 10    
gross cost: $4.00
net cost: $2.08

Sample output 3:

Enter start time: 1300
Enter length of call in minutes: 100    
gross cost: $40.00
net cost: $35.36

Sample output 4:

Enter start time: 1300
Enter length of call in minutes: 10    
gross cost: $4.00
net cost: $4.16    

////////////

//
//  main.cpp
//  Assignment 5
//
//  Created by Jake Anderson on 9/20/18.
//  Copyright © 2018 Jake Anderson. All rights reserved.
//
double grosscost1;
double netcost1;
double netcost2;
double netcost3;
double starttime;
double calllength;
double taxes=.04;
double rate=.40;
double hrdiscount=.15;
double grosscost = (calllength * .40) ;

#include <iostream>
# include <iomanip>
using namespace std;
int eighteenhundred=1800;
int eighthundred=800;
int two=2;
int main()
{

    cout << "Enter start time : ";
    cin >> starttime;

    cout << "Enter length of call in minutes : ";
    cin >> calllength;

    if (starttime >= eighteenhundred) {
        grosscost = (calllength * rate) ;
        netcost1= (grosscost/two) ;


    if (starttime <= eighthundred) {
        grosscost = (calllength * rate) ;
        netcost1= (grosscost/two) ;

    } else {

    if (calllength>=60) {
        netcost2= netcost1-(netcost1 * hrdiscount);
        netcost3= netcost2 + netcost2 * taxes;

    if (calllength<=59) {
        netcost3= netcost2 + netcost2 * taxes;
    }
    cout << fixed << std::setprecision(2) << "gross cost: $" << grosscost << endl;
    cout << fixed << std::setprecision(2) << "net cost: $" << netcost3 << endl;



}





}

}

}

Aucun commentaire:

Enregistrer un commentaire