Implement a simple calculator.
The calculator will execute basic arithmetic operations (add, subtract, multiply, divide and raise to the power) with decimal numbers and prints the current result when asked by the user.
The calculator keeps track at all time of the minimum and maximum calculated results.
The operator is given first and the operands after it on another line separated by whitespace.
The user is assumed to know how to use the program and therefore the program does not need to react to any unspecified errors.
Write a C++ program that :
-prints a prompt “%26gt;” on the screen
-waits for user input on the same line where the prompt is printed.
The input must be one of the following commands:
-Once the operation command is typed :
oif it is a +, - , / ,* or P the program waits for user input in the form of two numbers separated by a whitespace.
oif its is an =, H, M or Q the program prints an appropriate message.
-Several calculations can be done
I need help in the following project in c++?
This sounds like school work, its a fairly simple program. you will probably want to use the cout and cin function which needs you to include iostream.h
simply use cout to print to screen, ask for input etc. then take the input using cin and store it to a int variable.
a good way to do it would be to ask the user what they wish to do, eg subtract, divide and take that operator first, a symbol or a number to show choice. then the next line asks for the numbers to be input.
eg:
---------
Hello. what do you wish to do:
1 - subtract
2 - divide
3 - etc etc
%26gt;
-------------
then use an if function or maybe a switch to check what their input was and do the artithmatic.
so a very basic prgram may look like this:
it may have errors i havant checked it.
-----------------
#include %26lt;iostream%26gt;
int main()
{
int number;
cout %26lt;%26lt; "Hello, input a number" %26lt;%26lt; endl;
cin %26gt;%26gt;number;
return 0;
}
------
EDIT; i re read the req, you might find inputting the selection to a char better, then check the char to see what symbol is stored in it, eg + / -. and maybe use a char array for the number input. simple take the char array, check for the space. split the numbers into 2 and caste then to an int. sounds complicated but it isnt to hard.
sorry about spelling mistakes.
Reply:Not to be a creep but I really think you could learn a lot by doing your homework yourself.
Here are a couple of hints -
1. Parse the contents of the string entered by the user by using strtok() function - This function will allow you to break up a string into tokens. Just look this up on google.
2. Use a switch statement to find out which operator the user has entered and make your decisions based on that.
3. Set two global vars as min and max values - then when a calculation is done see if the final result is greater or lesser than the max or min value and substitute the new value into the appropriate variable.
This should help you figure out the rest
gladiolus
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment