Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3873044 • Letter: O

Question

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.

Explanation / Answer

#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(" Fahrenheit Celsius");

while(fahrenheit<125)

{

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

  

printf(" %f %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(" Enter a number");
scanf("%d",&n);

if(n>0)
{
total=total+n;
count++;
}
}while(n!=-1);
avg=total/count;
printf(" Average:%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