Question

*In C language *Without using Strings Write a program that uses a for loop to calculate...

*In C language

*Without using Strings

Write a program that uses a for loop to calculate the average cost of a dinner for a group of 10 people. Your program will use a function that will ask the user to enter in the price of each meal and return the value entered. Your program will calculate the total due for all 10 meals, the total tip using a defined constant of 20%, and the average price of a dinner. You program will then use a function to display the total due for the meals, the total tip using a defined constant of 20%, and the average price of a dinner.

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

SOLUTION-

I have solved the same problem . Below i have given the code and scrrenshot!

C CODE-

//------------C CODE------------
#include <stdio.h> //Header file
//function to get the price of meals
double Price ()
{
double rate;
printf ("Enter the price of meal :");
scanf ("%lf", &rate); // user will enter the price
return rate;
}

void display (double Due, double tip, double average) //To display the average tip, and total
{
printf ("Total Due : %lf\n", Due);
printf ("Total tip : %lf\n", tip);
printf ("Average price of dinner : %lf\n", average);
}

int main ()
{
double rate[10], Due = 0, tip = 0, average = 0;   //Declaration
for (int i = 0; i < 10; i++)    //To calculate total price
    {
      rate[i] = Price ();
    }
for (int i = 0; i < 10; i++)     //To calculate total Due
    {
      Due = Due + rate[i];
    }
tip = 0.2 * Due;               //Tip for meals
average = Due / 10.0;         //average
display (Due, tip, average);  
return 0;
}

SCREENSHOTS-

1 CODE 2 #include <stdio.h> //Header file 3 //function to get the price of meals 4 double Price () 5-{ 6 double rate; 7 print

16 printf (Average price of dinner : %1f\n, average); 17 } 18 | 19 int main() 20 { 21 double rate[10], Due = 0, tip 0, aver

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)

----------------PLEAESE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------

Add a comment
Know the answer?
Add Answer to:
*In C language *Without using Strings Write a program that uses a for loop to calculate...
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
  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • C++ Program Takes Strings Until 'QUIT' Input then Displays Strings in Reverse Order

    Write a C++ program that reads strings until "QUIT" input, which then displays all strings in the reverse order they were entered.Tell the user the program will read strings until "QUIT" is entered.LoopAsk user for a stringIf the string is "QUIT" break the loop, otherwise store data3. Inform user data will be displayed in reverse.4. Display ALL strings in reverse.5. Free the space used to store the strings.

  • Language - PYTHON Design a program that calculates the total amount of a meal purchased at a restaurant

    Language - PYTHONDesign a program that calculates the total amount of a meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15% tip and 7% sales tax. Display each of these amounts and the total.Please help, I have no idea where to begin. Thanks

  • Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and...

    Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and calculate the average score over a number of tests for a number of students. The program should: 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the scores...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • Python Simple Programming Write a program in Python that calculates the tip and total for a...

    Python Simple Programming Write a program in Python that calculates the tip and total for a meal at a restaurant. When your program is run it should ... Calculate the tip and total for a meal for a restaurant Print the name of the application "Tip Calculator" Get input from the user for cost of meal and tip percent Print the tip and total amounts. The formula for calculating the tip amount is: tip = cost of meal * (tip...

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • lab software using cygwin part1 part2 1 of 1 1. Write a shell program name it...

    lab software using cygwin part1 part2 1 of 1 1. Write a shell program name it "lab4q1.sh" to compare the two strings: a. Read the first string. b. Read the second string. c. If the strings are empty print "String Empty" and exit using the statement exit 1. d. Compare the two strings using the if and print longer string. e. If the size of both strings is same, then print that two strings are equal (use printf), otherwise, print...

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