Please write in C++ I nstructions: Part A. Code a for loop to print the Celsius
ID: 3906200 • Letter: P
Question
Please write in C++
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.
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
cout << "Fahrenheit --> Celsius" << endl;
// looping from 25 to 125
for(int fah = 25; fah <=125; fah++)
{
// calculating celsius
double cels = (5/9.0)*(fah-32);
// printing output
cout <<setw(5) << fah << " --> " << cels << endl;
}
}
/*SAMPLE OUTPUT
Fahrenheit --> Celsius
25 --> -3.88889
26 --> -3.33333
27 --> -2.77778
28 --> -2.22222
29 --> -1.66667
30 --> -1.11111
31 --> -0.555556
32 --> 0
33 --> 0.555556
34 --> 1.11111
35 --> 1.66667
36 --> 2.22222
37 --> 2.77778
38 --> 3.33333
39 --> 3.88889
40 --> 4.44444
41 --> 5
42 --> 5.55556
43 --> 6.11111
44 --> 6.66667
45 --> 7.22222
46 --> 7.77778
47 --> 8.33333
48 --> 8.88889
49 --> 9.44444
50 --> 10
51 --> 10.5556
52 --> 11.1111
53 --> 11.6667
54 --> 12.2222
55 --> 12.7778
56 --> 13.3333
57 --> 13.8889
58 --> 14.4444
59 --> 15
60 --> 15.5556
61 --> 16.1111
62 --> 16.6667
63 --> 17.2222
64 --> 17.7778
65 --> 18.3333
66 --> 18.8889
67 --> 19.4444
68 --> 20
69 --> 20.5556
70 --> 21.1111
71 --> 21.6667
72 --> 22.2222
73 --> 22.7778
74 --> 23.3333
75 --> 23.8889
76 --> 24.4444
77 --> 25
78 --> 25.5556
79 --> 26.1111
80 --> 26.6667
81 --> 27.2222
82 --> 27.7778
83 --> 28.3333
84 --> 28.8889
85 --> 29.4444
86 --> 30
87 --> 30.5556
88 --> 31.1111
89 --> 31.6667
90 --> 32.2222
91 --> 32.7778
92 --> 33.3333
93 --> 33.8889
94 --> 34.4444
95 --> 35
96 --> 35.5556
97 --> 36.1111
98 --> 36.6667
99 --> 37.2222
100 --> 37.7778
101 --> 38.3333
102 --> 38.8889
103 --> 39.4444
104 --> 40
105 --> 40.5556
106 --> 41.1111
107 --> 41.6667
108 --> 42.2222
109 --> 42.7778
110 --> 43.3333
111 --> 43.8889
112 --> 44.4444
113 --> 45
114 --> 45.5556
115 --> 46.1111
116 --> 46.6667
117 --> 47.2222
118 --> 47.7778
119 --> 48.3333
120 --> 48.8889
121 --> 49.4444
122 --> 50
123 --> 50.5556
124 --> 51.1111
125 --> 51.6667
*/