Question

In: Computer Science

Write a program that asks the user to enter an item’s wholesale cost and the markup...

Write a program that asks the user to enter an item’s wholesale cost and the markup percentage. It should then display the item’s retail price, which also includes a sales tax. For example, if the item’s wholesale cost is $5.00 and it’s markup is 100 percent, than the item’s retail price will be the marked up cost ($10.00) plus the sales tax (assume 6%), which would be $10.60). If an item’s wholesale cost is $10.00 and it’s markup is 50 percent, then the retail cost would be $15.90.

The program should have a method named “calculateRetail” that receives the wholesale cost and markup percentage as arguments and return the retail price of the item.

Solutions

Expert Solution

The programming language is not mentioned. Assuming it to be solved using C++. For any other languages (like JAVA or C), the structure of the program would be same, except that the keywords will be different.

The task is to get the item's wholesale cost and markup percentage. Markup percentage is calculated with respect to the wholesale cost. Also, sales tax are there (assuming 6%) which is applicable on the wholesale plus markup cost.


The required program (in C++) is given below:

#include<iostream>           //importing basic packages
#include<iomanip>
using namespace std;

double calculateRetail(double wholesale, double markup)           //function to calculate the retail price
{
   double r;
   r=wholesale+wholesale*markup/100;               //considering the markup percentage
   r=r+r*0.06;                   //consideration of the sales tax on the whole calculated value
   return r;                   //returning the value
}

int main()                       //main method
{
   double ws, mp, rp;
   cout<<"Enter the wholesale cost of the item: ";
   cin>>ws;                   //user input of the wholesale amount
   if(ws<=0)               //if the input is invalid, exit the program
   {
       cout<<"Please enter a valid wholesale cost value by running it again."<<endl;
       return 0;
   }
  
   cout<<"Enter the markup percentage: ";
   cin>>mp;                   //user input of the markup percentage
   if(mp<0)       //if the input is invalid, exit the program
   {
       cout<<"Please enter a valid markup percentage by running it again."<<endl;
       return 0;
   }
  
   rp=calculateRetail(ws, mp);           //calculating the retail price by calling the function and passing arguments
   cout<<fixed<<setprecision(2)<<endl;               //setting the result upto 2 decimals
   cout<<"The calculated Retail Price is: $"<<rp;           //displaying the result
   return 0;
}


Screenshot of the code:

It is assumed that correct markup percentage cannot be negative.


Output 1:

Output 2:

Output 3 (invalid input):

Output 4 (invalid input):

The same solution in JAVA is given below:

import java.util.*;         //import basic package
public class Main           //defining a class
{
    public static double calculateRetail(double wholesale, double markup)   //function to calculate the retail price
    {
        double r;
        r=wholesale+wholesale*markup/100;                //considering the markup percentage
        r=r+r*0.06;                    //consideration of the sales tax on the whole calculated value
        return r;                    //returning the value
    }


    public static void main(String []args)          // defining main method
    {
        double ws, mp, rp;
        Scanner sc=new Scanner(System.in);          //taking a Scanner object for input purpose
        System.out.printf("Enter the wholesale cost of the item: ");
        ws=sc.nextDouble();                    //user input of the wholesale amount
        if(ws<=0)                //if the input is invalid, exit the program
        {
            System.out.printf("Please enter a valid wholesale cost value by running it again.");
            System.exit(0);
        }
  
        System.out.printf("Enter the markup percentage: ");
        mp=sc.nextDouble();                    //user input of the markup percentage
        if(mp<0)        //if the input is invalid, exit the program
        {
            System.out.printf("Please enter a valid markup percentage by running it again.");
            System.exit(0);
        }
  
        rp=calculateRetail(ws, mp);     //calculating the retail price by calling the function and passing arguments
      
        System.out.printf("The calculated Retail Price is: $%.2f",rp);      //displaying the result upto 2 decimals

    }
}

Screenshot of the JAVA code:

Output of the JAVA code:


Related Solutions

Write a program that asks the user to enter an item’s wholesale cost and its markup...
Write a program that asks the user to enter an item’s wholesale cost and its markup percentage. It should then display the item’s retail price. For example: • If an item’s wholesale cost is 5.00 and its markup percentage is 100 percent, then the item’s retail price is 10.00. • If an item’s wholesale cost is 5.00 and its markup percentage is 50 percent, then the item’s retail price is 7.50. The program should have a method named calculateRetail that...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
In a file called LengthSum.java, write a program that: - Asks the user to enter a...
In a file called LengthSum.java, write a program that: - Asks the user to enter a string. - Asks the user to enter a second string. - Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please...
Write a program that asks the user to enter the total precipitation for each of the...
Write a program that asks the user to enter the total precipitation for each of the twelve months of the year into a list. The program should calculate and display the total precipitation for the year, the average monthly precipitation, and the months with the highest and lowest precipitation amounts. FYI: precipitation is measured in inches. Assume that precipitation amounts are floating-point numbers. You will need a list to store the precipitation amounts and another list to store the names...
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT