Write a program that simulates a simple calculation, C/C++ Programming

The program reads two numbers and a character (operator). If the character is "+" then sum is displayed. If it is "-"then difference is displayed. If it is "*" then product is displayed. If it is "/" then quotient is displayed. Use a switch statement.

#include 

using  namespace  std;
int  main  (  )

{

int  number1,  number2,  answer1,choice; float  answer2;

/*  menu  of  operation*/

cout<<"Menu  of  Operations"< cout<<"2  Division  "< cout<<"3  Addition  "< cout<<"4  Subtraction  "< /*end  of  menu*/

cout<<"enter  the  two  integer  numbers:  "<>number1>>number2;

cout<<"enter  your  choice:  "< cin>>choice;

/*  make  use  of  the  switch  case  construct
   to  make  decisions*/

switch  (choice)

{

case  1:

answer1=  number1  *  number2;

cout<

case  2:

answer2=  number1  /  number2;

cout<case  3:

answer1=  number1  +  number2;

cout<

case  4:

answer1=  number1  -  number2;

cout<

default:

cout<<"invalid  operator"<

}

return  0;

}

Posted Date: 8/21/2012 11:19:05 AM | Location : United States







Related Discussions:- Write a program that simulates a simple calculation, Assignment Help, Ask Question on Write a program that simulates a simple calculation, Get Answer, Expert's Help, Write a program that simulates a simple calculation Discussions

Write discussion on Write a program that simulates a simple calculation
Your posts are moderated
Related Questions
A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

In rPeANUt implement the "char getchar()" and "void printstring(char *str)" functions. Using these functions implement the following: void main() {    while (1) {       ch

finds the average for all assignments for an individual student float getAverageForStudent(float scores[20][10], int student, int numAssignments) {  }  // finds the average for

Syntax rules for writing a destructor function Its name is the similar as that of the class to which it belongs, except that the first character of the name is the symbol t

Find out the largest torque: A flat belt is taken in use to transmit torque from pulley A to pulley B as shown in figure given below. The radius of each pulley is 50mm and co

Consider a group of n robots, numbered R2D1 through R2Dn, and m tasks, numbered 1 through m. Tasks can be different and robots are specialized, hence a given robot can only perform

A: A dangling pointer arises while you use the address of an object after its lifetime is end. It may occur in situations such as returning addresses of automatic variables from a

Compiler Design - Limit In The Method Instructions

Define  F u n c t i o n?  T h e r e a r e t w o t y p e s o f f u n ct i o n b u i l t - i n f un ct i o n s a n d u

It is a feature in C++ to reduce name collisions in the global name space. This namespace keyword assigns a separate name to a library that allows other libraries to use the simila