Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my current code. I need help on why the math is not working properly. The output is completely off for some reason. Please

This is my current code. I need help on why the math is not working properly. The output is completely off for some reason. Please explain as to what I can do better with my code as well.

#include

#include

#include

int main() {

// Welcoming message

printf("Welcome to \"Temple\" store ");

printf(" ");

// Declaring variables

float itemPrice;

int quantity;

// Input for item price and creates a failed run using if statement

printf("Enter item price: ");

if (scanf("%f", &itemPrice) != 1 || itemPrice <=0) {

printf(" This is not a valid item price. Please run the program again ");

exit(1);

}

// Input for quantity amd creates a failed run using if statement

printf("Enter quantity: ");

double tempQuantity;

if (scanf("%lf", &tempQuantity) != 1 || tempQuantity <= 0 || modf(tempQuantity, &quantity) != 0 ) {

printf(" This is not a valid quantity order. Please run the program again ");

exit(1);

}

// Calculate cost

float cost = itemPrice * tempQuantity;

// Determine discount rate

float discountRate;

if (tempQuantity >= 1 && tempQuantity <= 49) {

discountRate = 0;

} else if (tempQuantity >= 50 && tempQuantity <= 99) {

discountRate = 0.1;

} else if (tempQuantity >= 100 && tempQuantity <= 149) {

discountRate = 0.15;

} else {

discountRate = 0.25;

}

// Calculate discount amount

float discountAmount = cost * discountRate;

// Calculate total

float total = cost - discountAmount;

// Display results

printf(" ");

printf("The item price is: $%.1f ", itemPrice);

printf("The order is: %.0lf item(s) ", tempQuantity);

printf("The cost is: $%.1f ", cost);

printf("The discount is: %.1f%% ", discountRate * 100);

printf("The discount amount is: $%.1f ", discountAmount);

printf("The total is: $%.1f ", total);

// Closing message

printf(" ");

printf("Thank You for using \"Temple\" store ");

exit(0);

}

THIS IS THE PROJECT THAT I AM TRYING TO CREATE

Project 2: revenue

Make a C program called revenue to calculate the revenue from a sale based on the unit price and quantity of a product input by the user. The discount rate is o 0% for the quantity purchased between 1 and 49 units. o 10% for the quantity purchased between 50 and 99 units. o 15% for the quantity purchased between 100 and 149 units. o 25% for the quantity purchased greater than or equal 150 units. Catch any invalid inputs (Negative numbers or Zeroes, or invalid entry format), output a warning message and end the program. Case (1) a successful run: Welcome to "Temple" store Enter item price: 10 Enter quantity: 60 The item price is: $10.0 The order is: 60 item(s) The cost is: $600.0 The discount is: 10.0% The discount amount is: $60.0 The total is: $540.0 Thank You for using "Temple" store Case (2) a failed run when the user entered a negative number for the item price: Welcome to "Temple" store Enter item price: -30 This is not a valid item price. Please run the program again Thank You for using "Temple" store Case (3) a failed run when the user entered a negative number for the quantity: Welcome to "Temple" store Enter item price: 10 Enter quantity: -90 This is not a valid quantity order. Please run the program again Thank You for using "Temple" store Case (4) a failed run when the user entered a decimal number for the quantity: Welcome to "Temple" store Enter item price: 10 Enter quantity: 90.7 This is not a valid quantity order. Please run the program again Thank You for using "Temple" store

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Marketing And Export Management

Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr

8th Edition

1292016922, 978-1292016924

More Books

Students also viewed these Algorithms questions

Question

3. Use the childs name.

Answered: 1 week ago

Question

Discuss the relationship between objective and strategy in pricing.

Answered: 1 week ago