1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ostrovityanka [42]
2 years ago
6

Write a calculator program using a switch statement that: a) Prompts the user to enter two numbers b) Prompts the user to select

between the four arithmetic operations using a choice from 1-4; for example, prompt the user with: "Choose 1) for add, 2) for subtract, 3) for multiply or 4) for divide)" c) Calculates the result of performing the selected operation on the numbers; and d) Displays the answer on the screen. (15 pts)
Computers and Technology
1 answer:
ollegr [7]2 years ago
6 0

Answer:

Following are the code in C language

#include <stdio.h> // header file

int main() // main method

{

   float f1; // variable declarartion

   float x,y; //variable declarartion

   int option;//variable declarations

   printf("Enter Two numbers:");

   scanf("%f%f",&x,&y);// input two number

   printf("Choose : 1: For add 2: For Subtract 3: for multiply 4: for divide");

   scanf("%d",&option); //read the choice

   switch(option)

   {

       case 1: //  for addition

   printf("%4f",x+y);

          break;

          case 2:// for subtraction

   printf("%4f",x-y);

          break;

          case 3: //for multiply

      printf("%4f",x*y);

          break;

      case 4: // for division

      f1=x/y;

   printf("%4f",f1);

          break;

      default: ////for invalid choice

          printf("Invalid choice") ;

  }

return 0;

}

Explanation:

In this program we taking a two input from user of float types after taking input,the switch statement is used case 1 for addition,case 2 for subtraction case 3 for multiplication,case 4 for division and default for invalid choice .

Output

Enter Two numbers:2.5

2.5

Choose : 1: For add 2: For Subtract 3: for multiply 4: for divide:4

1.000000

You might be interested in
Modify your main.c file so that it allocates a two dimensional array of integers so that the array has 20 rows of 30 integers in
Alexandra [31]

Answer:

Explanation:

b

7 0
2 years ago
Listening to music on giggl, join!<br><br> link will be in comments, copy and paste
Ilya [14]

Answer:

umm, we can't say any links

Explanation:

7 0
2 years ago
Read 2 more answers
Hello everyone. New ppl on Ro.blox? I want to play sometime.
alexira [117]

Answer:

Hello :)

Explanation:

Yesh i play Ro.blox, maybe u or me could friend each other

6 0
2 years ago
Read 2 more answers
Size of the information in each field of the database
bonufazy [111]

It can approximately be around 20 basically it depends on your text how long or short the text is

3 0
2 years ago
Define additional characteristics such as font weight or style for an html tag
Bas_tet [7]
<span>Define additional characteristics such as font weight or style for an html tag:
- attributes</span>
4 0
2 years ago
Other questions:
  • Which OS, in your opinion, manages multiprocessing in the most efficient manner?
    14·1 answer
  • It is not possible to convert a numbered list to a bulleted list in Word 2007. T or F
    13·1 answer
  • Among the web programming languages, css is used to define _____ of the web page
    5·1 answer
  • Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
    7·1 answer
  • What operating system type uses icons to represent programs
    9·2 answers
  • which kind of device does a computer need in order to provide information to a person or something else
    7·1 answer
  • What field in an IPv4 packet is altered to prioritize video streaming traffic over web surfing traffic?
    7·1 answer
  • How is the cia triad used to evaluate encryption methods?
    6·1 answer
  • When you're working on an image, it's a good idea to make a ____________ of the image, so that you'll have the original image in
    12·2 answers
  • Suppose a packet is 10K bits long, the channel transmission rate connecting a sender and receiver is 10 Mbps, and the round-trip
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!