1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
PSYCHO15rus [73]
3 years ago
5

Write a program named as calcPrice.c that formats product information entered by the user and calculate the total amount of purc

hase.

Computers and Technology
1 answer:
Colt1911 [192]3 years ago
4 0

Answer:

Here is the calcPrice.c program:

#include <stdio.h>   //to use input output functions

int main(void)  {  //start of main method

   int itemNo, month, day, year, quantity;  //declares variables to hold item number, quantity, and date

   float unitPrice; //declare variable to hold price per unit

   printf("Enter item number: ");  // prompts user to enter item number

   scanf("%d", &itemNo);  //reads item number from user and stores it in itemNo variable

   printf("Enter unit price: ");  // prompts user to enter unit price

   scanf("%f", &unitPrice);  //reads input unit price and stores it in unitPrice variable

   

    printf("Enter quantity: ");  //prompts user to enter quantity

   scanf("%d", &quantity);  //reads input quantity and stores it in quantity variable

   printf("Enter purchase date (mm/dd/yyyy): ");  //prompts user to enter purchase date

   scanf("%d/%d/%d", &month, &day, &year);  //reads input date and stores it in month, day and year variables

    float totalAmount = unitPrice * quantity;  //computes the total amount

   printf("\nItem\tUnit Price\tQTY\tPurchase Date\tTotal Amount\n");  //displays the item, unit price, qty, purchase data and total amount with tab space between each

   printf("%d\t$%5.2f\t%d\t%.2d/%.2d/%d\t$%5.2f\n", itemNo, unitPrice,quantity, month, day, year,totalAmount);   }    //displays the values of itemNo, unitPrice, quantity, month, day, year and computed totalAmount with tab space between each

Explanation:

Lets suppose user enters 583 as item number, 13.5 as unit price, 2 as quantity and 09/15/2016 as date so

itemNo = 583

unitPrice = 13.5

quantity = 2

month = 09

day = 15

year = 2016

totalAmount is computed as:

  totalAmount = unitPrice * quantity;

 totalAmount = 13.5* 2

totalAmount = 27.00

Hence the output of the entire program is:

Item    Unit Price      QTY     Purchase Date   Total Amount      

583     $  13.50           2           09/15/2016         $  27.00  

The screenshot of the program along with its output is attached.

You might be interested in
Katarina is deciding whether to buy a desktop or a laptop computer. What will most likely help Katarina make her decision?
Gnesinka [82]
Laptops are portable decides , while desktops remain in one plcae
4 0
3 years ago
Read 2 more answers
Write a program that accepts any number of homework scores ranging in value from 0 through
Dimas [21]

Answer:

This program is written in Java programming language.

It uses an array to store scores of each test.

And it also validates user input to allow only integers 0 to 10,

Because the program says the average should be calculated by excluding the highest and lowest scores, the average is calculated as follows;

Average = (Sum of all scores - highest - lowest)/(Total number of tests - 2).

The program is as follows (Take note of the comments; they serve as explanation)

import java.util.*;

public class CalcAvg

{

public static void main(String [] args)

{

 Scanner inputt = new Scanner(System.in);

 // Declare number of test as integer

 int numTest;

 numTest = 0;

 boolean  check;

  do

  {

   try

   {

     Scanner input = new Scanner(System.in);

    System.out.print("Enter number of test (1 - 10): ");

    numTest = input.nextInt();

    check = false;

    if(numTest>10 || numTest<0)

     check = true;

   }

   catch(Exception e)

    {

     check = true;

   }

  }

  while(check);

  int [] tests = new int[numTest];

//Accept Input

for(int i =0;i<numTest;i++)

{

System.out.print("Enter Test Score "+(i+1)+": ");

tests[i] = inputt.nextInt();

}

           //Determine highest

           int max = tests[0];

           for (int i = 1; i < numTest; i++)

           {

               if (tests[i] > max)

               {

                   max = tests[i];

               }

           }

           //Determine Lowest

           int least = tests[0];

           for (int i = 1; i < numTest; i++)

           {

               if (tests[i] < least)

               {

                   least = tests[i];

               }

           }

           int sum = 0;

           //Calculate total

           for(int i =0; i< numTest;i++)

           {

               sum += tests[i];

           }

           //Subtract highest and least values

           sum = sum - least - max;

           //Calculate average

           double average = sum / (numTest - 2);

           //Print Average

           System.out.println("Average = "+average);

           //Print Highest

           System.out.println("Highest = "+max);

           //Print Lowest

           System.out.print("Lowest = "+least);

}

}

//End of Program

6 0
3 years ago
Leah wants to add an image to her updated presentation, so she wants to access the Help interface. What should Leah do to access
PSYCHO15rus [73]

Answer: 0

Explanation: 1/2

3 0
2 years ago
Read 2 more answers
1) What is Database? List its Uses.<br>​
Serggg [28]

Answer:

a database stores a large sum of data

Explanation:

its used to keep track of things like student names bank accounts and other things

7 0
2 years ago
A line beginning with a # will be transmitted to the programmer’s social media feed.
zhenek [66]

Answer:

True?

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • This is the main work area of your computer.
    7·1 answer
  • The init() command initializes the task queue and scheduler data structures. run Next Task() MUST run to completion whatever tas
    9·1 answer
  • Which option allows you to view slides on the full computer screen?
    11·1 answer
  • True or false A ClassB fire involves live electrical equipment
    5·1 answer
  • Fill in the blank.
    7·1 answer
  • What is the definition of a digital signal?
    14·1 answer
  • Which of the following is a programming language that permits Web site designers to run applications on the user's computer?
    15·1 answer
  • Which term describes a visual object such as a picture a table or text box
    15·2 answers
  • Write a python program to change variable value of your previous result percentage to your current percentage of mid-term
    13·1 answer
  • _____ is a system in which a finite set of words can be combined to generate an infinite number of sentences.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!