Question

In: Computer Science

Write a program that allows the user to enter two integers and a character If the...

Write a program that allows the user to enter two integers and a character If the character is A, add the two integers If it is S, subtract the second integer from the first else multiply the integers Display the results of the arithmetic

Solutions

Expert Solution

Since you have not specified the programming language to be used in the question, so I am provided you the code in C++ programming language. In case you want the solution in any other language, then let me know in the comment.

CODE :

#include <iostream>
using namespace std;

int main()
{
int a,b;
char ch;
cout<<"Enter the two integers : ";
cin>>a>>b;
cout<<"Enter the character : ";
cin>>ch;
switch(ch){
case 'A': cout<<"The sum of the integers is : "<<a+b;
break;
case 'S': cout<<"The difference of the integers is : "<<a-b;
break;
default: cout<<"The product of the integers is : "<<a*b;
break;
}

return 0;
}

SAMPLE OUTPUT1 :

SAMPLE OUTPUT2 :

SAMPLE OUTPUT3 :

If you have any doubt/query regarding the above solution, then let me know in the comment. If the solution helps, do give an upVote to this answer.


Related Solutions

1. Write a program that will ask the user to enter a character and then classify...
1. Write a program that will ask the user to enter a character and then classify the character as one of the following using only IF-ELSE and logical operators. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • Integer • Lower Case Vowel • Upper Case Vowel • Lower Case Consonant • Upper Case Consonant • Special Character
In java, write a program that asks the user to enter a character. Then pass the...
In java, write a program that asks the user to enter a character. Then pass the character to the following methods. isVowel() – returns true if the character is a vowel isConsonant() – returns true if the character is a consonant changeCase() – if the character is lower case then change it to upper case and if the character is in upper case then change it to lower case. (return type: char) Example output is given below: Enter a character...
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a Python program to: ask the user to enter two integers: int1 and int2. The...
Write a Python program to: ask the user to enter two integers: int1 and int2. The program uses the exponential operator to calculate and then print the result when int1 is raised to the int2 power. You also want to calculate the result when int1 is raised to the .5 power; however, you realize that it is not possible to take the square root of a negative number. If the value for int1 that is entered is a negative number,...
Program must be in C Write a program that allows the user to enter the last...
Program must be in C Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate in two different arrays. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. Example (Letters and numbers with underscore indicate an input):...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
Write a java program that lets the user to enter any two integers and weave them...
Write a java program that lets the user to enter any two integers and weave them digit by digit and print the result of weaving their digits together to form a single number. Two numbers x and y are weaved together as follows. The last pair of digits in the result should be the last digit of x followed by the last digit of y. The second-to-the-last pair of digits in the result should be the second-to- the-last digit of...
1. Write a Python program to: ask the user to enter two integers: int1 and int2....
1. Write a Python program to: ask the user to enter two integers: int1 and int2. The program uses the exponential operator to calculate and then print the result when int1 is raised to the int2 power. You also want to calculate the result when int1 is raised to the .5 power; however, you realize that it is not possible to take the square root of a negative number. If the value for int1 that is entered is a negative...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT