Question: Modify the program to use a for loop to ask the user for the math operator. Use an input function such as getchar() to input

 Modify the program to use a for loop to ask theuser for the math operator. Use an input function such as getchar()

Modify the program to use a for loop to ask the user for the math operator. Use an input function such as getchar() to input the character. You should display a menu to the user such as Menu: +, -, /, * each time the user is supposed to input a character.

#include void main) int n1- 20; int n2 5; char ch ch = '+'; printf("ch-%c ", ch); switch (ch) { case .+': printf("Sum %d ", n1+n2); case : printf("Diff-%d ", n1-n2); case '/': printf("Division-%d ", n12); case .*.. printf("Product-%d ", n1*n2); default: printf("invalid operator|n") printf("ch -n", ch); switch (ch) { case .+' : printf("Sum %d ", n1 + n2): case '-': printf("Diff-%d ", n1 - n2); case ./. : printf("Division-%d ", n1 / n2); case .*.. printf("Product=%d ", n1*n2); default: printf("invalid operator n"); ch/ printf( "ch = %c ", ch); switch (ch) { case .+': printf("Sum= %d ", n1 + n2); case-: printf("Diff-%d ", n1 - n2); case ./. : printf("Division-%d ", n1 / n2); case '*': printf("Product=%d ", n1*n2); default: printf("invalid operator "); printf("ch ", ch); switch (ch) { case .+': printf("Sum= %d ", n1 + n2); case-: printf("Diff-%d ", n1 - n2); case ./. : printf("Division-%d ", n1 / n2); case '*': printf("Product=%d ", n1*n2); default: printf("invalid operator "); printf("ch ", ch); switch (ch) { case .+': printf("Sum %d ", n1 + n2); case-: printf("Diff-%d ", n1 - n2); case ./. : printf("Division-%d ", n1 / n2); case '*': printf("Product-%d ", n1*n2); default: printf("invalid operator ")

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 Databases Questions!