Question

Write source code in C++ that prompts the user to enter two numeric values. Store these...

Write source code in C++ that prompts the user to enter two numeric values. Store these values in double variable objects named first and second. Write your program to display the following calculations:

  • the first minus the second
  • the second minus the first
  • the first added to the second
  • the first multiplied by the second,
  • the first divided by the second.

What happens when second is equal to zero?

Homework Answers

Answer #1
#include<iostream>

using namespace std;

int main()
{
   double first, second;
   
   cout<<"Enter value for first: ";
   cin>>first;
   
   cout<<"Enter value for second: ";
   cin>>second;
   
   cout<<(first-second)<<endl;
   cout<<(second-first)<<endl;
   cout<<(first+second)<<endl;
   cout<<(first*second)<<endl;
   if(second==0)
      cout<<"Infinity"<<endl;
   else
      cout<<(first/second)<<endl;
   return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
6.         Write a single statement that prompts the user to enter their age in years and places...
6.         Write a single statement that prompts the user to enter their age in years and places the integer value in a variable named age. 7.         Can a program place more than one statement on the same program line? 8.         Write a short code segment in Python that prompts the user to enter the number of quarters, dimes, nickels and pennies they have, compute the total value and print that value.
Binary Search Tree Code in Java Write a program that prompts user to enter however many...
Binary Search Tree Code in Java Write a program that prompts user to enter however many numbers they want to add to the binary search tree. Then have the user input numbers until the tree contains that many elements. If the user enters a number that already exists in the tree, then a message should be displayed "Number is already in the tree". Once all elements are added to the tree print its contents in sorted order. Assume all user...
Write a Java program and Flowchart that prompts the user to enter two characters and displays...
Write a Java program and Flowchart that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. Suppose the following characters are used to denote the majors: I: Information Management C: Computer Science A: Accounting
Write an application that prompts a user for two integers and displays every integer between them....
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. ------------------------------------------------------------------------------------------------- import java.util.Scanner; public class Inbetween {     public static void main (String args[]) {         // Write your code here     } }
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
PLease code a C++ program that prompts a user to enter 10 numbers. this program should...
PLease code 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 10 numbers and the average of the 10 numbers please use file i/o and input measures for Handling Errors in C++ When Opening a File
Write a Java program that prompts the user to enter his/her name (first and last). Names...
Write a Java program that prompts the user to enter his/her name (first and last). Names are often expressed alphabetically as last name comma space first name. Display the user's alphabetical name and its length. Then output the user's initials. Finally, display the ASCII values of the initials with a space between them. Sample Output (input shown in italics) Enter your full name Jane Doe Your alphabetical name Doe, Jane is 9 characters long Your initials are JD ASCII of...
4.29 (Square of Asterisks) Write an application that prompts the user to enter the size of...
4.29 (Square of Asterisks) Write an application that prompts the user to enter the size of the side of a square, then displays a hollow square of that size made of asterisks. Your program should work for squares of all side lengths between 1 and 20. I keep getting the error: "AsteriskSquare.java:2: error: class Main is public, should be declared in a file named Main.java public class Main ^ 1 error"
Write a program that prompts the user to enter time in 12-hour notation. The program then...
Write a program that prompts the user to enter time in 12-hour notation. The program then outputs the time in 24-hour notation. Your program must contain three exception classes: invalidHr, invalidMin, and invalidSec. If the user enters an invalid value for hours, then the program should throw and catch an invalidHr object. Follow similar conventions for the invalid values of minutes and seconds. This needs to be done in C++ There needs to be a separate header file for each...
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b,...
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b, c, and then computes the results of the following logical operations, in sequence: !a || !b++ && c (a-1 || b/2) && (c*=2) (a-- || --b) && (c+=2) a || !(b && --c)