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
Implement a menu driven real estate catalogue system that allows users to perform various catalogue maintenance and search tasks.  You are only allowed to use the C programming la

Problem: (a) Show the Java approach to event processing by explaining how event handling works in Java. Make use of a suitable example to support your answer. (b) Describe

Aim: To implement a program for dynamic data structure(linked list). Code:                       class node {             int data;             node *next;

Programming Assignment # 1 C and UNIX   The purpose of this assignment is to get you more familiar with Unix/Linux and those constructs of C that are not part of C++. Write a C

Project Description: We are seeking online invoice OCR solution. That will help us to automate accounts payable function. User should be able to use the offered pdf file or s

Rules of Operator Overloading It is a function defined to an operator with new term or meaning. It cannot produce new operator. It cannot modified the meaning of th


array itself is a pinter.explain

char P[100]; double X=533.8*22500; sprintf(P,"%f %u",X,(unsigned int)X); MessageBox(P,"SSS"); //12010500.000 12010499

C Program to FIND VOWELS   void main() {           char str[50];           int ac=0, ec=0, ic=0, oc=0, uc=0;           int i,stln,vc,word=1;           clrscr