Question: Assuming int x = 0; int y = 0; int value = 0; char op_code = '0'; a) Write code to ask users to enter

Assuming

int x = 0; int y = 0; int value = 0; char op_code = '\0';

a) Write code to ask users to enter integers for x and y and a character either '+' or '-' or '*' for the op code.

b) Write an if else statement to perform the following: if op_code is '+' add x and y then store the result in the value variable. If op_code is '-' subtract y from x then store the result in the value variable. If op_code is '*' then multiply x and y andstore the result in the value variable. If op_code is anything else set value to -1.

c) The above if else statement is not efficient. Replace it using a switch statement.

2) (8 points)

Write a for loop that keeps asking users to enter a positive integer for 1000 times. Count the number of odd integers. Output the result after the for loop is done using a field width of 5 with leading zeros. For example if the odd integer count is 376 then the output must show 00376. Declare necessary variables with proper naming convention and initialization at declaration.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!