Create a program that will ask user to input two numbers and choose from the four mathematical operations and display the answer. (use nested if or switch statement) Here is your sample screen output: Input First Number: Input Second Number: Choose Arithmetic Operations 1. ADD 2. SUBTRACT 3. MULTIPLY 4. DIVIDE 5. Exit Select Operation (1-5): _ The SUM of the two numbers is:
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Can you revise this as like this in the picture
#include <stdio.h>
int main() {
char ch;
double firstN, secondN;
printf("Enter an choice (+, -, *, /): ");
scanf("%c", &ch);
printf("Enter two numbers: ");
scanf("%lf %lf", &firstN, &secondN);
switch (ch) {
case '+':
printf("The addition of %.1lf and %.1lf is %.1lf", firstN, secondN, firstN + secondN);
break;
case '-':
printf("The Subtraction of %.1lf anf %.1lf is %.1lf", firstN, secondN, firstN - secondN);
break;
case '*':
printf("The multipication of %.1lf * %.1lf is %.1lf", firstN, secondN, firstN * secondN);
break;
case '/':
printf("The division of %.1lf and %.1lf is %.1lf", firstN, secondN, firstN / secondN);
break;
default:
printf("Invalid input");
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images