Display in C++ 1) What is the displayed value of count3? int i, ntemps = 4; // t
ID: 3916366 • Letter: D
Question
Display in C++
1) What is the displayed value of count3?
int i, ntemps = 4; // total number of temp values = 4
int temp; // temperature value
int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
int sum1 = 0, sum2 = 0, sum3 = 0;
for ( i = 0; i < ntemps; i++)
{
cout << “Enter temperature value”
cin >> temp;
if (temp > 50) count1++;
if (temp > 40 && temp <= 60) count2++;
if (temp > 40 || temp <= 50) count3++;
sum1 = temp;
sum2 = sum2 + temp;
sum3 = temp + 10;
}
cout << count1 << count2 << count3 << sum1 << sum 2<< sum3 << i;
Assume the user has entered the following 4 temperature values: 50, 60, 70, 80
2) What is the displayed value of i?
int i, ntemps = 4; // total number of temp values = 4
int temp; // temperature value
int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
int sum1 = 0, sum2 = 0, sum3 = 0;
for ( i = 0; i < ntemps; i++)
{
cout << “Enter temperature value”
cin >> temp;
if (temp > 50) count1++;
if (temp > 40 && temp <= 60) count2++;
if (temp > 40 || temp <= 50) count3++;
sum1 = temp;
sum2 = sum2 + temp;
sum3 = temp + 10;
}
cout << count1 << count2 << count3 << sum1 << sum 2<< sum3 << i;
Assume the user has entered the following 4 temperature values: 50, 60, 70, 80
Explanation / Answer
1.
count3 will be count of temperatures which are more than 40 OR less than or equal to 50.
As all 4 values satisfies this condition, count3 becomes 4.
2.
i is initialized with 0. in for loop, the loop breaks, when i become more than or equal to ntemps=4. So i will be 4 at last.