Question

In: Computer Science

C++ Program: Write a program that prompts the user for two numbers and stores them in...

C++ Program:

Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if an operation has happened that does not result in a correct calculation. In other words, make sure to test your code for error cases. You can safely assume I will only give your program integers (I will give your program only decimal digits).

Solutions

Expert Solution

C++ Program:

#include <iostream>

using namespace std;

int main() {

int a,b,sum,prod,div;

cout<<"Enter first integer: ";

cin>>a;

cout<<"Enter second integer: ";

cin>>b;

sum=a+b;

cout<<"Sum of these two integers is : "<<sum<<endl;

prod=a*b;

cout<<"Sum of these two integers is : "<<prod<<endl;

try{

if(b!=0){

div=a/b;

cout<<"Div of a and b is : "<<div;

}

else

throw b;

}

catch(int b){

cout<<"Cannot divide by 0";

}

}

if you like the answer please provide a thumbs up.


Related Solutions

C++ Write a program that prompts the user to enter 50 integers and stores them in...
C++ Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs separated by a ';'. An example of the program is shown below: list[0] = 15 is the sum of: ----------------------...
You must write a C program that prompts the user for numbers and multiplies them using...
You must write a C program that prompts the user for numbers and multiplies them using "a la russe" multiplication. No input is allowed at execution time (no command line input). The program MUST DISPLAY YOUR BANNER LOGO as part of a prompt to the user. A menu must allow the user to put in two numbers at the same time or each of two numbers one at a time. The valid range of values for each number is 0...
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a c++ code that prompts the user to enter three float numbers and print them...
Write a c++ code that prompts the user to enter three float numbers and print them in acsending order
Write a C program that prompts the user to enter three sets of five double numbers...
Write a C program that prompts the user to enter three sets of five double numbers each. (You may assume the user responds correctly and doesn’t enter non-numeric data.) The program should accomplish all of the following: a. Store the information in a 3×5 array. b. Compute the average of each set of five values. c. Compute the average of all the values. d. Determine the largest value of the 15 values. e. Report the results. Each major task should...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT