Identify and correct the error(s) in each of the following:
a) if ( age >= 65 );
cout « "Age is greater than or egoial to 65" « endl; else
cout « "Age is less than 65 « endl";
b) if ( age >= 65 )
cout « "Age is greater than or equal to 65i! « endl;
else;
cout « "Age is less than 65 « endl";
c) int x = 1, total;
while { x <= 10 ) { total += x;
d) VJhile ( x <= 100 ) total += x;
e) while ( y > 0 ) {
cout « y « endl;
_____________________________________
What does the following program print?
// Ex. 2.15: ex02_15.cpp
// What does this program print?
^include <iostream>
/
using std::cout; using std::endl;
// function main begins program execution int main()
int y;
int x = 1; int total = 0;
//declare y
// initialize x
// initialize total
while ( x <= 10 ) { y = x * xi cout « y « endl; total += y;
II loop 10 tiraes
// perform calculation
// output result
// add y to total
// increment counter x
} II end while
cout « "Total is " « total « endl; //display result
_____________________________________________
Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. De¬velop a C++ program that uses a while structure to input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. Af¬ter processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.
Enter the gallons used (-1 to end):\12.8 I" Enter the miles driven: 287 " 7 - ^-- / The miles / gallon for this tank was-22.421875
Enter J:he_ gallons^ used,('ril_to_end) :rl6.3
Enter the miles driven f=2 00-—^-~rr^"===
The miles 7 gallon-for this tank was T9."417475
Enter the*gallons used (-1 to end): 5
Enter the miles driven: 120
The miles / gallon for this tank was 24.000000
Enter the gallons used (-1 -'to end):
The overall average miles/gallon was 21.601423
____________________________________________________________
Develop a C++ program that will determine whether a department-store customer has ex¬ed the credit limit on a charge account. For each customer, the following facts are available:
a) Account number (an integer)
b) Balance at the beginning of the month
c) Total of all items charged by this customer this month
d) Total of all credits applied to this customer's account this month
e) Allowed credit limit
The program should use a while structure to input each of these facts, calculate the new bal-
ance (= beginning balance + charges - credits) and determine whether the new balance exceeds the
customer's credit limit. For those customers whose credit limit is exceeded, the program should dis¬
play the customer's account number, credit limit, new balance and the message "Credit limit
exceeded."
_________________________________________________________
(Another Dangling-Else Problem) Modify the following code to produce the output shown Use proper indentation techniques. You must not make any changes other than inserting braces The compiler ignores indentation in a C++ program. We eliminated the indentation from the following code to make the problem more challenging. [Note: It is possible that no modification is necessary.]
if ( y == 8 )
if ( x == 5 )
cout « »@@@&is.« « endl;
else
cout « "#%%%$" « endl;
cout « "$$$$$" « endl;
cout « "&&&£&" « endl;
a) Assuming x = 5 and y = 8/the following output is produced.
@@@@@
$$$$$
&&&&&
b) Assuming x = 5 and y = 8, the following output is produced.
@@@@@
c) Assuming x = 5 and y = 8, the following output is produced
@@@@@
&&&&&
____________________________________
The factorial of a nonnegative integer n is written n\ (pronounced "n factorial") and is de¬nned as follows:
n\ = n • (n - !)•(«-2) •... • 1 (for values of n greater than to 1)
and
n\ = 1 (for n = 0 or n = 1). For example, 5! = 5-4-3-2-l, which is 120. Use while structures in each of the following:
X
) Write a program that reads a nonnegative integer and computes and prints its factorial. ) Write a program that estimates the value of the mathematical constant e by using the for-/ mula:
^c) Write a program that computes the value of e* by using the formula
x2 x3
___________________________________
أرجو المساعده ولكم مني جزيل الشكر والعرفان
