Im doing a calculator project for my c++ class but my operations dont compute properly and i cant quite figure out whats wrong any input would be greatly appreciated.

//Program Name: Calc

//Author: Charles Covington

//Date: Feb. 20, 2007

//Description : This is a simple calculator

#include 
#include 
#include 
using namespace std;
//prototypes
string upconv(string instring);
void help();

//begin main program
int main () {
//declarations
double memory; //contains value in memory
double display; //contains contents of display
double number; //contains input number
string strInput; //contains an operator or command
char firstChar; //first char of input
char secondChar; //second char of input
int inputLength; //length of input

//show user program description
cout << "Enter ? for help" << endl;
while(true) {
//read input
cin >> strInput;
strInput = upconv(strInput);
//extract first character
firstChar = strInput[0];
inputLength = strInput.length();
if(inputLength==1) {
switch(firstChar) {
case '+':
cin >> number;
display = display + number;
break;
case '-':
break;
case '*':
break;
case '/':
break;
case '=':
break;
case '?':
help();
break;
case 'I':
break;
case 'N':
display = display * -1;
break;
case 'E':
break;
default:
cout <<"Error invalid command" <<endl;
}//end switch
}//end then
else { //2 character command
if(firstChar == 'M') { //memory command
secondChar = strInput[1];
switch(secondChar) {
case 'S':
memory = display;
break;
case 'R':
display = memory;
cout << "Memory equals " << endl;
break;
case '+':
display = memory + display;
break;
case 'C':
break;
default:
cout << "Invalid memory command"<<endl;
}//end switch
}//end of
else {
}
}//end else
cout << display << endl;
}//end while

return 0;
}//end main



string upconv(string instring) {
string newstring=instring;
int len = instring.length();
for(int i=0; i
newstring[i]= toupper(instring[i]);
}//end for
return newstring;
}//end upconv

void help() {
//display help screen
cout << "HELP" << endl;

Recommended Answers

All 5 Replies

It would help if you would learn how to use tabs and spaces correctly so that your program is easier to read/understand. As it is few people, if anyone at all, will bother to read it. And what are lines 9 through 11 supposed to do? Must be a copy/paste error.

commented: It's endemic isn't it - salem +6

sorry this is my firsst c++ prgram
the includes should be: iostream, string, and cmath. not sure why those didnt copy over

what compiler are you using?

microsoft visual C++ 6.0

It would help if you would learn how to use tabs and spaces correctly so that your program is easier to read/understand. As it is few people, if anyone at all, will bother to read it. And what are lines 9 through 11 supposed to do? Must be a copy/paste error.

sorry this is my firsst c++ prgram

So are you going to format your code so we can read it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.