Question: Im having issues with a variable (salesTax) being uninitialized and the program skipping the second cin, what is the simplest way to fix this issue.

Im having issues with a variable (salesTax) being uninitialized and the program skipping the second cin, what is the simplest way to fix this issue. I don't know what I'm doing wrong. This is written in C++.

#include

#include

using namespace std;

int main() {

cout << "Mia Dimson ";

cout << "0107 ";

cout << "Assignment 3 ";

int units;

short unitCost, totalAmountDue, salesTax;

cout << "Please enter the cost of each candy bar: ";

cin >> unitCost;

if (unitCost > 0.01 and unitCost < 0.2) {

salesTax = .01;

return salesTax;

}

if (unitCost > 0.2 and unitCost <= 0.4) {

salesTax = .02;

return salesTax;

}

if (unitCost > 0.4 and unitCost <= 0.6) {

salesTax = .03;

return salesTax;

}

if (unitCost > 0.6 and unitCost <= 0.8) {

salesTax = .04;

return salesTax;

}

if (unitCost >= 0.8 and unitCost <= 1) {

salesTax = .05;

return salesTax;

}

cout << salesTax << endl;

cout << "Please enter the quantity: " << endl;

cin >> units;

totalAmountDue = units * unitCost + salesTax * unitCost;

cout << "Your total amount is $" << totalAmountDue << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!