Chapter 4 Control Structures: Part (Web design templates) 1 137 18
Chapter 4 Control Structures: Part 1 137 18 19 Console.WriteLine( “The sum is: ” + sum ); 20 } 21 } 4.7 a) product = 25, x = 6; b) quotient = 0, x = 6; 4.8 a) Error: Missing the closing right brace of the whilebody. Correction: Add closing right brace after the statement ++c;. b) Error: Semicolon after else results in a logic error. The second output statement will always be executed. Correction: Remove the semicolon after else. 4.9 The value of the variable z is never changed in the while structure. Therefore, if the loop- continuation condition (z>=0) is true, an infinite loop is created. To prevent the infinite loop, z must be decremented so that it eventually becomes less than 0. EXERCISES 4.10 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. Develop a C# program that will input the miles driven and gallons used (both as doubles) for each tankful. The program should calculate and display the miles per gallon obtained for each tankful and print the combined miles per gallon obtained for all tankfuls up to this point. All average calculations should produce floating-point results. 4.11 Develop a C# application that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: a) Account number 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 input as integers each of these facts, calculate the new balance (= beginning balance + charges credits), display the new balance and determine if the new balance exceeds the customer’s credit limit. For those customers whose credit limit is exceeded, the program should display the message, Credit limit exceeded. 4.12 Write a C# application that uses looping to print the following table of values: N 10*N 100*N 1000*N 1 10 100 1000 2 20 200 2000 3 30 300 3000 4 40 400 4000 5 50 500 5000 4.13 (Dangling-Else Problem) Determine the output for each of the following, when xis 9and y is 11 and when xis 11 and yis 9. Note that the compiler ignores the indentation in a C# program. Also, the C# compiler always associates an else with the previous if unless told to do otherwise
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services