this is the code:
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
const double PERC19 = 0.2;
const double PERC49 = 0.3;
const double PERC99 = 0.4;
const double PERC100 = 0.5;
const double Price = 99.00;
double totalCost, originalAmount, discountAmount, dRate;
int numberofSold;
cout << "Enter the number of units sold\n";
cin >> numberofSold;
// Input Validation
if (numberofSold < 0) {
cout << "Input should be a positive number\n";
exit(0);
}
originalAmount = numberofSold * Price;
if(numberofSold >= 10 && numberofSold <= 19){
cout << "test";
discountAmount = originalAmount * PERC19;
totalCost = originalAmount - discountAmount;
}
if(numberofSold >= 20 && numberofSold <= 49){
cout << "test";
discountAmount = originalAmount * PERC49;
totalCost = originalAmount - discountAmount;
}
if(numberofSold >= 50 && numberofSold <= 99){
cout << "test";
discountAmount = originalAmount * PERC99;
totalCost = originalAmount - discountAmount;
}
if(numberofSold >= 100){
cout << "test";
discountAmount = originalAmount * PERC100;
totalCost = originalAmount - discountAmount;
}
cout << totalCost;
}
this is it's output:
PS C:\C_programs\first assing> .\asign.exe
Enter the number of units sold
5
3.95253e-323
PS C:\C_programs\first assing>
when given an input of 5, why would this be outputted? 5 does not qualify for any of the if statements. totalCost should be null, but instead it does 3.95253e-323 instead when run on my computer.
on replit.com, it outputs 395 instead, which is the calculation for the first if statement (not the input val one), dispite not actually running the statement.