Need help with if/else statement formatting

So basically, I am trying to write a program that calculates the price per unit and percent off per unit of software sold. The program is supposed to calculate the percent off based on the amount of units inputted by the user, and then display it. My problem is that when I run my code, I get two outputs for the price per unit, and it screws up my total price. Do I have my if/else statements formatted correctly?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//This program calculates the price per unit and balance due for units of software.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
    //set an integer for the amount of units sold
    int unitsSold;
    //set the double for the and the balance due
    double balanceDue;
    //set values for the price breaks on amount of units sold
    const float tenToNineteen = 0.80;
    const float twentyToFortynine = 0.70;
    const float fiftyToNinetynine = 0.60;
    const float oneHundredPlus = 0.50;
    
    //set the value for the price per unit sold
    
    float pricePer = 99.0;
    float pricePerUnit;
    
    //request amount of software units sold
    cout << "How many software units sold? ";
    cin >> unitsSold;
    //if the amount sold that is inputted is negative, end the program.
    if (unitsSold < 0)
        cout << "Invalid response. Run program again. ";
    else;
    //display the amount of units sold
    cout << "Software units sold: " << setw(39) << unitsSold << endl;
    //display the price per unit based on the amount of units sold
    if (unitsSold >= 0 && unitsSold <= 9)
        {
        cout << fixed << showpoint << setprecision(2);
        cout << "Price per unit: " << setw(34) << "$" << setw(10) << pricePer << endl;
        }
        else if (unitsSold >= 10 && unitsSold <= 19)
        {
        cout << fixed << showpoint << setprecision(2);
        pricePerUnit = pricePer * tenToNineteen;
        cout << "Price per unit: " << setw(34) << "$" << setw(10) << pricePerUnit << endl;
        }
        else if (unitsSold >= 20 && unitsSold <= 49)
        {
        cout << fixed << showpoint << setprecision(2);
        pricePerUnit = pricePer * twentyToFortynine;
        cout << "Price per unit: " << setw(34) << "$" << setw(10) << pricePerUnit << endl;
        }
        else if (unitsSold >= 50 && unitsSold <= 99)
        {
        cout << fixed << showpoint << setprecision(2);
        pricePerUnit = pricePer * fiftyToNinetynine;
        cout << "Price per unit: " << setw(34) << "$" << setw(10) << pricePerUnit << endl;
        }
        else ( unitsSold >= 100);
        {
        cout << fixed << showpoint << setprecision(2);
        pricePerUnit = pricePer * oneHundredPlus;
        cout << "Price per unit: " << setw(34) << "$" << setw(10) << pricePerUnit << endl;
        }
    //calculate and display the balance due
    balanceDue = pricePerUnit * unitsSold;
    cout << "Balance due: " << setw(37) << "$" << setw(10) << balanceDue;
    
    return 0;   
}


If this helps, here is my desired output vs my actual output:

DESIRED

How many software units sold? 5
Software Units Sold: 5
Price Per Unit: $ 99.00
Balance Due: $ 495.00

ACTUAL

How many software units sold? 5
Software units sold: 5
Price per unit: $ 99.00
Price per unit: $ 49.50
Balance due: $ 247.50
Hi,

Remove line 29, it doesn't do anything.

Line 56: an else cannot have a condition, it looks like you are trying to give it one. Make it an else if and remove the semicolon.

At the moment, this is what causes the second "Price per unit: "

Use the else to catch bad input, if I put in 2,000,000 could that be an error ?
Thank you so much! it is working perfectly now :)
Well, it works... until you input 9 or less... :)
Topic archived. No new replies allowed.