Question

Objectives: Use the while loop in a program Use the do-while loop in a second program...

Objectives:

Use the while loop in a program

Use the do-while loop in a second program

Use the for loop in a third program

Instructions:

Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format:

Fahrenheit Celsius

25 ?

. .

. . . .

. .

Turn in the source and the output from Part A.

Part B. Code a while loop to read in and total any number of positive integers terminated with a -1 as a sentinel. Print the average of the values after the loop is finished. Run with at least 4 or 5 numbers – make some of them negative numbers which should not be included in the total or average. The approach should be:

1. Define total and count and set them to 0

2. Read in a number

3. While number != -1

3.1 If number >0

3.1.1 Total += number

3.1.2 Count ++

3.2 Read in another number

4. Print the average of the positive numbers

5. Stop

Turn in the source and the output from Part B.

Part C. Code a do while loop to make change for a customer. Input the amount of money put into a vending machine. Change that value to cents. Input the amount of the purchase. Change that value to cents. Subtract the two values. Determine the customer’s change in number of quarters, dimes, nickels, and pennies, using integer arithmetic. Hint:

cents / 25 = number of quarters

cents % 25 = remaining cents to change into dimes, nickels, etc.

Keep making change for different purchases until the user tells you to stop. Make change for 3 or 4 purchases. Turn in the source and 3 or 4 outputs from Part C.

Run:

See each individual part for the run information.

cleardot.gif

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

#include <stdio.h>

int main(void) {

// your code goes here

float fahrenheit,celsius;

printf("Celsius temperatures for Fahrenheit temperatures 25 to 125");

fahrenheit=25;

printf("\nFahrenheit Celsius");

while(fahrenheit<125)

{

celsius = (fahrenheit - 32) * 5 / 9;

  

printf("\n %f\t %f",fahrenheit,celsius);

fahrenheit=fahrenheit+1;

}   

return 0;

}

Output:

Celsius temperatures for Fahrenheit temperatures 25 to 125

Fahrenheit Celsius

25.000000 -3.888889

26.000000 -3.333333

27.000000 -2.777778

28.000000 -2.222222

29.000000 -1.666667

30.000000 -1.111111

31.000000 -0.555556

32.000000 0.000000

33.000000 0.555556

34.000000 1.111111

35.000000 1.666667

36.000000 2.222222

37.000000 2.777778

38.000000 3.333333

39.000000 3.888889

40.000000 4.444445

41.000000 5.000000

42.000000 5.555555

43.000000 6.111111

44.000000 6.666667

45.000000 7.222222

46.000000 7.777778

47.000000 8.333333

48.000000 8.888889

49.000000 9.444445

50.000000 10.000000

51.000000 10.555555

52.000000 11.111111

53.000000 11.666667

54.000000 12.222222

55.000000 12.777778

56.000000 13.333333

57.000000 13.888889

58.000000 14.444445

59.000000 15.000000

60.000000 15.555555

61.000000 16.111111

62.000000 16.666666

63.000000 17.222221

64.000000 17.777779

65.000000 18.333334

66.000000 18.888889

67.000000 19.444445

68.000000 20.000000

69.000000 20.555555

70.000000 21.111111

71.000000 21.666666

72.000000 22.222221

73.000000 22.777779

74.000000 23.333334

75.000000 23.888889

76.000000 24.444445

77.000000 25.000000

78.000000 25.555555

79.000000 26.111111

80.000000 26.666666

81.000000 27.222221

82.000000 27.777779

83.000000 28.333334

84.000000 28.888889

85.000000 29.444445

86.000000 30.000000

87.000000 30.555555

88.000000 31.111111

89.000000 31.666666

90.000000 32.222221

91.000000 32.777779

92.000000 33.333332

93.000000 33.888889

94.000000 34.444443

95.000000 35.000000

96.000000 35.555557

97.000000 36.111111

98.000000 36.666668

99.000000 37.222221

100.000000 37.777779

101.000000 38.333332

102.000000 38.888889

103.000000 39.444443

104.000000 40.000000

105.000000 40.555557

106.000000 41.111111

107.000000 41.666668

108.000000 42.222221

109.000000 42.777779

110.000000 43.333332

111.000000 43.888889

112.000000 44.444443

113.000000 45.000000

114.000000 45.555557

115.000000 46.111111

116.000000 46.666668

117.000000 47.222221

118.000000 47.777779

119.000000 48.333332

120.000000 48.888889

121.000000 49.444443

122.000000 50.000000

123.000000 50.555557

124.000000 51.111111

#include<stdio.h>

int main()
{
int total=0,count=0;
signed int n;
int avg;
do
{
printf("\nEnter a number");
scanf("%d",&n);

if(n>0)
{
total=total+n;
count++;
}
}while(n!=-1);
avg=total/count;
printf("\nAverage:%d ",avg);
return 0;
}

Enter a number3

Enter a number6

Enter a number6

Enter a number-2

Enter a number3

Enter a number-1

Average:4

Add a comment
Know the answer?
Add Answer to:
Objectives: Use the while loop in a program Use the do-while loop in a second program...
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
  • Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10...

    Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repeatedly prompt the user for a price in the form xX.xx, where X denotes a digit, or to enter q' to quit 3. When a price is entered a. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q)...

  • C++ HW Question Your program will simulate a simple change maker for a vending machine. It...

    C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...

  • (In Python 3) Write a program with total change amount as an integer input, and output...

    (In Python 3) Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes So...

  • I need this answer as soon as possible if anyone can help! Thank you! Place the...

    I need this answer as soon as possible if anyone can help! Thank you! Place the lines of code in the correct order so that the program requests an input amount less than one dollar, and then makes change for the given amount using the least number of coins print("tCents:", cents) remainder amount print("Nickels:", nickels, end"") remainder 96-10 remainder 25 nickels-remainder 5 amount int(input(Enter amount of change:") dimes remainder// 10 cents- remainder print( Quarters", quarters, end"") quarters remainder I/ 25...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • C++ Write a program that helps a young student learn to make change. Use the random...

    C++ Write a program that helps a young student learn to make change. Use the random number generator to generate change amounts between1¢ and 99¢. Ask the user how many quarters, dimes, nickels and pennies they need to make that amount. Determine whether the coins specified by the user total the specified amount and give them feedback on their answer including whether they used the minimum or optimum number of coins to produce the amount. Sample output of a program...

  • 2. Write a JAVA program that prints the numbe r of quarters, dimes, nickels, and pennies...

    2. Write a JAVA program that prints the numbe r of quarters, dimes, nickels, and pennies that a customer should get back as change. Declare and initialize all memory locations as integers. On Output show the original change amount as a monetary amount with the two positions of decimal. Run your program once by performing a compile-time initializations using 92 cents for the calue to be converted. Go into your source code and change the 92 to 27. Return the...

  • All items at a "Penny Fair" are priced less than $1.00. Write a program that makes...

    All items at a "Penny Fair" are priced less than $1.00. Write a program that makes change with a minimum number of coins when a customer pays for an item with a one dollar bill. Prompt for the item price in cents, report the change due, and the number of coins of each denomination required. Use only quarters, dimes, nickels, and pennies for change (no 50 cent pieces). See sample output but your program should work for any item price....

  • write a python program that use while and for loop.

    Write a Python program that- Uses a while loop to produce a table that shows the conversion of degrees Celsius to degrees Fahrenheit between 0 degrees Celsius and 100 degrees Celsius. Theconversion formula is Fahrenheit = Celsius * 9 / 5 + 32-Uses a for loop to produce a table that shows the conversion of degrees Fahrenheit to degrees Celsius between 0 degrees Fahrenheit and 100 degrees Fahrenheit. Theconversion formula is Centigrade = (Fahrenheit – 32) * 5/9.-Each conversion table...

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

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