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
C Program to copy the contents of a file: void main()    {   ifstream fin("input.txt");   ofstream fout("output.txt");   char ch;   while (fin)       {

you are to create a text adventure game that uses pointers. You have a rich, eccentric Uncle Billy who is soon to be deceased. How soon.....oops......he''s gone. He has left yo

Hello, I would like to know if you can help in C programs that work on android.

Step 1 Define the start of the program    It should be noted that within C all commands should end in a semi-colon. For most of your programs the definition of a program header as

A function REPAT is specified below. Function REPAT(c in Char, i in Int, s in mString) return in mString pre 1 ≤ i ≤ the length of s. post The returned value is a string identic

Develop a Student class that has the following header file: #ifndef STUDENT_H #define STUDENT_H #include #include #include using namespace std; class Stu

Explain the Function Prototype? The Functions must be declared before they are used, ANSI C provides for the new function declaration syntax called as the function prototype,

Unions A union is also like a structure, except that only single variable in the union is stored in the allocated memory at a time. It is a collection of mutually exclusive var

Program is to perform all the functions that are performed in a super bazaar: class stock   {   private:     int itno;     char itname[20];     char brname[20];

replace character into string and return value of string that are replaced