assignment20 - { cout << "Enter a number:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/*Write a simple calculator program. Ask the user if s/he wants to add ('+') subtract ('-'), multiply ('*') or divide ('/') and then ask for the number. Perform the operation with the given number. Start the "display" at zero. Stop when the user enters 'X' (for exit). See the screen shot below for a sample run. Use a Do. .While loop and "if" statements.*/ #include <iostream> # using namespace std; u int main() { char sign; double signnumber; double currenttotal = 0; d do { cout << "Current total is " << currenttotal << endl; cout << "Enter an operation: + - * / (or enter X to exit):"; cin >> sign; c if (sign == '+')
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { cout << "Enter a number: "; cin >> signnumber; currenttotal = (currenttotal + signnumber); } if (sign == '-') { cout << "Enter a number: "; cin >> signnumber; currenttotal = (currenttotal - signnumber); } if (sign == '*') { cout << "Enter a number: "; cin >> signnumber; currenttotal = (currenttotal * signnumber); } if (sign == '/') { cout << "Enter a number: "; cin >> signnumber; if (signnumber > 0) { currenttotal = (currenttotal / signnumber); } else cout << "Can not divide by zero!" << endl; currenttotal = (currenttotal + 0); } }while (sign != 'X'); } }...
View Full Document

This note was uploaded on 01/11/2010 for the course CMPSC 101 taught by Professor Drobish,renee during the Summer '07 term at Pennsylvania State University, University Park.

Page1 / 2

assignment20 - { cout << "Enter a number:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online