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...

  • 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...

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • The following program sorts the array of numbers entered by the user and prints out the...

    The following program sorts the array of numbers entered by the user and prints out the elements in descending order. It has many errors. Debug the code and show the output. #include <stdio.h> #define N 4 void desc(float *a, float *b) float tp; tp=a; a=b; b=tp; int main() int i, j, ii, mark[N] ; for (ii==0;ii<N;ii++) printf("Enter the %d th element of your array: \n",ii); scanf("%d", mark[ii]); printf("You have entered the following array: \n"); for (ii=0,ii<N,ii++) printf("%d ", mark[ii]); printf("\n...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

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
ADVERTISEMENT