Question

13. Write the program with at least two functions to solve the following problem (excluding the...

13. Write the program with at least two functions to solve the following problem (excluding the main function).

The members of a board are considering voting for a tax increase for 100 items. They are considering an increase of 5% for each item. Write a program that will prompt for and accept the current price for each item, then calculate and display their individual price after tax increases. At the end of the program, print the total price before and after the tax increase for all 100 items

this is my current code

#include <stdio.h>


float original(float price[100])
{
   int i;
   for(i=0; i<10; i++)
   {
       printf("Please enter prices.\n");
       scanf("%f",&price[i]);
       printf("The original price %f and the new price %f.", price[i], tax[i]);
   }
  
}

float newprice(float price[100])
{
   float tax[100];
   printf("Origianl price Tax increase\n");
   float totalprice = 0;
   float totaltax = 0;
   int i;
   for(i=0; i<100; i++)
   {
       tax[i]=1.08*price[i];
       totalprice += price[i]-tax[i];
       totaltax += tax[i]
       printf("%f %f %f \n", price[i], tax[i], price[i] + tax[i]);
   }

   printf("total price and total tax is = %f %f",totalprice, totaltax);
}


int main()
{
   float price[100];
   original(price, tax);
   newprice(price);
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <stdio.h>
float original(float price[]) //function to read 100 item original prices and return total price.
{
int i;
float originalTotalPrice = 0;
for(i=0; i<100; i++) //loop for read 100 item prices.
{
printf("Please enter item %d price: ", i+1); //prompting the user to enter each item price.
scanf("%f",&price[i]); //reading price in to array.
originalTotalPrice += price[i]; //adding each item original price.
}
return originalTotalPrice; //returning total original price of 100 items.
}
float newprice(float price[]) //function to calculate after tax increase and printing and return total price of 100 items after tax increase.
{
int i;
float newPriceOfEachItem, eachItem5PerTax, newTotalPrice = 0;
for(i=0; i<100; i++) //to access 100 item prices.
{
eachItem5PerTax = (price[i]*5)/100; //calculating each item 5 percent tax.
newPriceOfEachItem = price[i] + eachItem5PerTax; //increasing tax for each item.
printf("Item %d price after increasing of tax: %f\n", i+1, newPriceOfEachItem); //printing prices after tax increase.
newTotalPrice += newPriceOfEachItem; //adding each price after tax increase.
}
return newTotalPrice; //returning total all 100 item prices after tax increase.
}
int main()
{
float price[100], originalTotalPrice, newTotalPrice; //variable declarations.
originalTotalPrice = original(price); //calling the function to read 100 item original prices.
newTotalPrice = newprice(price); //calling the function to calculate new price and printing.
printf("\nTotal price of all 100 items before tax increase: %f\n", originalTotalPrice); //printing total price before tax increase.
printf("Total price of all 100 items after tax increase: %f\n", newTotalPrice); //printing total price after tax increase.
return 0;
}

#include <stdio.h> float original (float price[]) //function to read 100 item original prices and return total price. int i;27 28 29 30 31 32 33 34 35 36 int main() El { float price[100], originalTotalPrice, newTotalPrice; //variable declarations. o

For showing the output I have taken 5 items as example:

#include <stdio.h> float original (float price[]) //function to read 100 item original prices and return total price. int i;27 28 29 30 31 32 33 34 35 int main() El float price [5], originalTotalPrice, newTotalPrice; //variable declarations. origina

output:

enter Please enter item 1 price: 5 Please enter item 2 price: 7 Please enter item 3 price: 2 Please enter item 4 price: 4 Ple

Note: my friend if you have any questions or queries comment below. I am happy to answer you all questions. I will sort out your queries. Thank you my friend.

Add a comment
Know the answer?
Add Answer to:
13. Write the program with at least two functions to solve the following problem (excluding the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...

  • C program. Using do-while loop for this question. Question: write a program to calculate the average...

    C program. Using do-while loop for this question. Question: write a program to calculate the average of first n numbers. output: Enter the value of n : 18 The sum of first 18 numbers =171 The average of first 18 numbers = 9.00 my code couldn't give me the right avg and sum. Please help. #include<stdio.h> int main() {     int num;     int count =0;     int sum=0;     float avg;      printf("Enter the value of n: ");    ...

  • C program Classwork_3.3: Correct the program below that will read two numbers: number of drinks and...

    C program Classwork_3.3: Correct the program below that will read two numbers: number of drinks and number of sandwiches, and display the total bill calculated as: Total bill = Number of Drinks X 5.50 + Number of Sandwiches X 10.00 Answer the questions below. C-Program with error: Write the correct program here: #include<stdio.h> int main (void) floats numberofDrinks, numberofSandwiches; float totalBilling: printf("Enter number of Drinks \n"); scanf("%d",&numberofdrinks); printf("Enter number of Sandwiches\n") scanf("%f",&numberofSandwiches); totalbilling = numberofDrinks *5.50 + numberofsandwiches/10.00; printf("Total bill...

  • Given the following C program, rewrite the program and use C++ header files, C++ constants, inline...

    Given the following C program, rewrite the program and use C++ header files, C++ constants, inline functions and C++ I/O. Please note that the standard C++ library header file, which defines the I/O functions is named <iostream>. This header file contains the definition of the std namespace. /* Convert this program into a C++ program. */ #include <stdio.h> #include <conio.h> #define PI 3.141592 float reactance(float c,float f) { return 1/(2*PI*f*c); } int main() { float frq,cap,xc; printf("Enter frequency => ");...

  • Write a MATLAB program that implements the algorithm designed in the Topic 1 "Non-Linear Flowchart" and...

    Write a MATLAB program that implements the algorithm designed in the Topic 1 "Non-Linear Flowchart" and "Creating a Flowchart" assignments previously implemented in C. Compare and contrast the C and MATLAB versions of your codes. convert this to a matlab program #include <stdio.h> int main() { int a; printf("Enter first number: "); scanf("%d", &a); int b; printf("Enter second number: "); scanf("%d", &b); int limit; printf("Enter limit: "); scanf("%d", &limit); printf("\nFirst number: %d\n", a); printf("Second number: %d\n", b); int c; c...

  • Using the code below, Complete the C program main.c to stop execution if the user attempts...

    Using the code below, Complete the C program main.c to stop execution if the user attempts a divide by 0. #include <stdio.h> int main() { float a, b; printf("Input two integers to divide the first by the second\n"); scanf("%f%f", &a, &b); printf("%f/%f = %.2f\n", a, b, a/b);    return 0; }

  • Debug the following matrix program in C: // Program to read integers into a 3X3 matrix...

    Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) {         char size;         double Matrix[size][size+1];         printf("Enter 9 elements of the matrix:\n");         int i;         for (i = 0: i <= size: i++)     {       int j = 0;       for (; j <= size++; j++){         scanf("%d", matrix[i--][4])       }     }         Display(Matrix,9);         return 0; void...

  • I need the programming to be in language C. I am using a program called Zybook...

    I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at...

    answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at least three (3) syntax errors that will compilation to fail with errors. Identify each of these errors and specify the solution. [2 marks each, 6 marks in total] cause #include <stdio.h> void main (void) float height; float area; printf "input height of the rectangle: ") scanf( "%f", &height) printf"input length of the rectangle: scanf"", &length); height length; area printf( area of rectangle %f high...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT