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
Which statement gives an advantage of multicellular organisms?
slava [35]

Answer:

D and B

Explanation:

Multicellular organisms thus have the competitive advantages of an increase in size without its limitations. They can have longer lifespans as they can continue living when individual cells die. Multicellularity also permits increasing complexity by allowing differentiation of cell types within one organism.

4 0
2 years ago
Read 2 more answers
1| def saveUserProfile(firstName, lastName, age, height, country):
Feliz [49]

Answer:

Joyner

David

USA

1.8

30

Explanation:

def saveUserProfile(firstName, lastName, age, height, country):

This is the definition of function named saveUserProfile which accepts the following parameters:

  • firstName
  • lastName
  • age
  • height
  • country

filename = lastName + firstName + ".txt"

When the file is created it will be named as the lastName and firstName string combined with .txt as extension. For example if the lastName contains the name string Joyner and firstName contains the name David then the file created to be written is named as JoynerDavid.txt

outputFile = open(filename, "w")

This statement uses open() method in write mode and uses outputFile object to access the file. "w" represents write mode i.e. file is opened in write mode to write on it.

a) Joyner is written on line 1 of that file because of the following statement of above function:

print(lastName, file = outputFile)

This statement prints the string stored in lastName i.e. Joyner. Here outputFile opens the file in "w" write mode and writes the last name to the first line of the file.

b) David is written on line 2 of that file because of the following statement of above function:

print(firstName, file = outputFile)

This statement prints the string stored in firstName i.e. David. Here outputFile opens the file in "w" write mode and writes the first name to the second line of the file.

c) USA is written on line 3 of that file because of the following statement of above function:

print(country, file = outputFile)

This statement prints the data stored in country i.e. USA. Here outputFile opens the file in "w" write mode and writes the country name to the third line of the file.  

d) 1.8 is written on line 4 of that file because of the following statement of above function:

print(height, file = outputFile)

This statement prints the value stored in height i.e. 1.8. Here outputFile opens the file in "w" write mode and writes the height value to the fourth line of the file.  

e) 30 is written on line 5 of that file because of the following statement of above function:

print(age, file = outputFile)

This statement prints the value stored in age parameter of function saveUserProfile i.e. 30. Here outputFile opens the file in "w" write mode and writes the age value to the fifth line of the file.  

7 0
3 years ago
In what way, if any, can your social media presence affect your chances of getting a job in social media?
Leno4ka [110]

Answer:

Your social media postings can help you secure a job too, not just it being effective in a bad way.

Explanation:

Your content can give hiring managers an overall idea of your personality, what you are passionate about, how you interact with people in group discussions and how previous colleagues feel about you through recommendations and so on. All of these give you an advantage in securing a job.

7 0
2 years ago
The format that you will use on your works cited page when the entry is longer than one line is__________.
OverLord2011 [107]

The format that you will use on your works cited page when the entry is longer than one line is to second and all subsequent lines need to be indented half an inch.

<h3>What kind of formatting is used on a works cited page?</h3>

In the formatting of the Works on Cited page, the layout is that "Title the page Works Cited, do put it on the center and in plain text (no italics, bold, or underline). etc.

Note that the format to use when  your works cited page  entry is more than one line is to second and all subsequent lines need to be indented half an inch.

Learn more about cited page from

brainly.com/question/1382377

4 0
2 years ago
2-3 Calculating the Body Mass Index (BMI). (Programming Exercise 2.14) Body Mass Index is a measure of health based on your weig
Luden [163]

Answer:

weight = float(input("Enter your weight in pounds: "))

height = float(input("Enter your height in inches: "))

weight = weight * 0.45359237

height = height * 0.0254

bmi = weight / (height * height)

print("Your BMI is: %.4f" % bmi)

Explanation:

*The code is written in Python.

Ask the user to enter weight in pounds and height in inches

Convert the weight into kilograms and height into meters using given conversion rates

Calculate the BMI using given formula

Print the BMI

5 0
3 years ago
Other questions:
  • Which of the following are examples of algorithms? (Select all that apply, if any do.)
    15·2 answers
  • A type of bridge that relies on a curved, semi-circular structure for support
    5·1 answer
  • A company is a Microsoft 365 reseller. The company does not provide managed services or direct customer support. You need to pro
    10·1 answer
  • How does microchip work
    12·1 answer
  • It takes 2 seconds to read or write one block from/to disk and it also takes 1 second of CPU time to merge one block of records.
    10·1 answer
  • How do you know if a remote host is alive or not?
    5·1 answer
  • A benefit of flashcards is that they are
    7·2 answers
  • When a JSP page is compiled, what is it turned into?
    11·1 answer
  • How to learning algothrim bett
    5·1 answer
  • What is a phone made out of dna
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!