1. ## Calculator

Take it and compile it, see how it works.
Updated again, sad how you didn't see the progress.
Also, I have no idea how to "name" versions, like 1.2.3.4, so I went for what felt right
Code:
```/*
Name: Calculator 1.2.2
Author: Silkey Katzewurzt
Date: 26-07-07 21:49
Description: A calulator!
*/
#include <iostream>
using namespace std;
int sub(int a,int b);
int mul(int a,int b);
int divi(int a,int b);
int main() {
char command;
int a;
int number = 0;
int saved = 0;
string avCom = "+,-,*,/";
string instructions = "\nThis works just like a normal calculator,"
" available commands are: \nTo reset your calculation, "
"type in 'c' and then any number,\nand it will reset to 0."
"\nTo save, type in 'm' and then any number."
"\nTo load a saved calculation, type in 'l' and then any number."
"\nTo see these instructions, type in i and then any number.\n";
cout<<instructions;
cout<<"\n\n"<<number<<"\n";
while(true){
cout<<"\n";
cin>>command>>a;

switch(command) {
case '+':
cout<<number<<" plus "<<a<<" equals to "<<add(number,a);
break;
case '-':
cout<<number<<" minus "<<a<<" equals to "<<sub(number,a);
number = sub(number,a);;
break;
case '*':
cout<<number<<" multiplied by "<<a<<" equals to "<<mul(number,a);
number = mul(number,a);
break;
case '/':
cout<<number<<" divided by "<<a<<" equals to "<<divi(number,a);
number = number/a;
break;
case 'm':
cout<<number<<" has been saved.\n";
saved = number;
break;
case 'l':
number = saved;
break;;
case 'c':
number = 0;
break;
case 'i':
cout<<instructions;
break;
default:
cout<<"No such command.\n";
break;
}
}
}
return a+b;
}
int sub(int a,int b) {
return a-b;
}
int mul(int a,int b) {
return a*b;
}
int divi(int a,int b) {
return a/b;
}
/*
26-07-07 22:02
26-07-07 22:39
26-07-07 23:15
*/```

2. Sorry, what's the question?

Apart from how to fold long lines, these are equivalent
Code:
```  cout << "This is a very long line indeed";
cout << "This is a "
"very long line "
"indeed";```

3. Its ok

Why have you included iostream twice? You only need to include header files once if its not a project ( ie: single source code file )

4. Code:
```                    case 'r':
break;```
And this code does what?

By the way, on a calculator, you usually use "c" to "clear" things, so why not use that here, and "m" is "store in memory" - since you don't have a separate key, "l" is as good as any for restoring from memory.

You may also want to add upper case to your selections, such that if you hit "caps-lock", it still does the same thing - but that's optional.

By the way, why do you set "number=0" when you save it?

--
Mats

5. Hmm, I didn't do
Code:
`#include <iostream>`
twice on purpose, so to speak, that was a mistake...
Actually I have no idea how that could ever happen!

Also, I thought of using both lowercase and uppercase, but how do I do that?
Code:
```switch(a) {
case 'a'|'A':
}```
I tried that before, but it didn't seem to work.

I changed the save from 's' to 'm', same with clear.
The "reset" should have a number=0; in it, but hm, I think it was when I was adding new options, I put the number=0 in the save, instead of in the reset.

It should be good now, the first post has been edited to your liking!

6. Originally Posted by Salem
Sorry, what's the question?

Apart from how to fold long lines, these are equivalent
Code:
```  cout << "This is a very long line indeed";
cout << "This is a "
"very long line "
"indeed";```
Oh sorry, is this a help forum?
I thought I could post things that I have made.
Sorry! >.<

7. To check for multiple cases, you need different case statements, such as

Code:
```   case 'a':
case 'A':
...```
You can pile a heap of case-statements on the same place, such as if you wanted to convert a hex-number, you could do something like this:

Code:
```  switch(c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
num = c - '0';
break;

case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
num = c - 'a' + 10;
break;

case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
num = c - 'A' + 10;
break;

case '\0':
return result;

default:
printf("invalid number...\n");
break;
}  // switch
result <<= 4;
result += num;
...  some sort of loop ...```
Note: I'm not suggesting that this is a GOOD way to convert hex-string to binary - just giving it as an example of dealing with multiple case-statements that do the same thing. [Actually, a good compiler should convert this into very similar code to comparing the bounds of digits and 'a' .. 'f', so it shouldn't be too bad - but I don't generally trust compilers to do a really great job unless I've checked it out for this purpose]

--
Mats

8. Originally Posted by matsp
To check for multiple cases, you need different case statements, such as

Code:
```   case 'a':
case 'A':
...```
You can pile a heap of case-statements on the same place, such as if you wanted to convert a hex-number, you could do something like this:

Code:
```  switch(c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
num = c - '0';
break;

case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
num = c - 'a' + 10;
break;

case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
num = c - 'A' + 10;
break;

case '\0':
return result;

default:
printf("invalid number...\n");
break;
}  // switch
result <<= 4;
result += num;
...  some sort of loop ...```
Note: I'm not suggesting that this is a GOOD way to convert hex-string to binary - just giving it as an example of dealing with multiple case-statements that do the same thing. [Actually, a good compiler should convert this into very similar code to comparing the bounds of digits and 'a' .. 'f', so it shouldn't be too bad - but I don't generally trust compilers to do a really great job unless I've checked it out for this purpose]

--
Mats
Thanks my friend! *hug*

9. And by the way, version numbers can be just about anything. But often they are x.y.z(-w), where:

x is the MAJOR release. When this changes, something BIG has happened, e.g. Windows NT was version 4. Windows 2000 was 5. Normally, you expect software to "break compatibility" to some extent when changing this number. Say for example you added a way to "save" old calculations in your calculator. When you move from version 1.x to 2.0, you may decide to change the format so that the new version can do more things with the saved file - it should still (if possible) support the OLD version for loading, but files saved with the new version may not operate correctly with an old version of the calculator. [1]

y is the MINOR release. Changes here are feature improvements or major bug-fixes. Normally shouldn't cause any compatibility issues, saved files should be back- and forwards compatible, and such.

z is used to indicate small changes, such as small feature enhancements, bug-fixes and so on. (I'm not sure what this is called - I think some people call it release-number).

w is sometimes used as a "fix-release", e.g. a security problem or some bug-fix - this should not change any user-visible behaviour (except of course if the "user" is trying to use the security hole, or the software no longer crashes when you visit a particular web-site or whatever the bug that was fixed is).

Some people (and I have done this before now) include a "build number" or "build date-time" each time the application is built (at least for "release", e.g. you plan to send it out).

[1] It is generally a good idea to have some sort of "version" in a save-file, so that the software can at least detect that the file is "wrong version", rather than just doing random stupid things (crashing, incorrect results, garbled stuff being printed, and so on).

--
Mats

10. You seem like a very wise man, do you have any suggestion what a confused SilkeyWurzt like me could do now, either a new program, or improve this calculator? Not that there is much to do with it now.

11. Rather than use long switch statements, there is a function that will make your job easier. http://www.cppreference.com/stdstring/tolower.html
(Or http://www.cppreference.com/stdstring/toupper.html.)

You can just go
Code:
```switch(tolower(c)) {
case 'a':
std::cout << "You entered 'a'.\n";
break;
}```
and it will handle 'a' and 'A' in the same way.

I actually think that matsp's explanation is better than this one, but anyway, here's the Wikipedia entry: http://en.wikipedia.org/wiki/Software_versioning

12. Originally Posted by SilkeyWurzt
You seem like a very wise man, do you have any suggestion what a confused SilkeyWurzt like me could do now, either a new program, or improve this calculator? Not that there is much to do with it now.
Two obvious things:
- Supporting parenthesis will excercise some of your skill in programming. For example, if you want to calculate (2+2) * (3+4) it should become 28, rather than 2 + (2*3) +4 = 12. [That's what your application does now].
- Somewhat related is to support standard mathematical priorities in an expression - such that 4 + 3 *7 calculates to 4 + (3 *7) = 25, rahter than (4 + 3)*7 = 49. Not all calculators support this, but if you have an advanced one, it will.

Parenthesis is probably the easier task to perform first, and then use the code you've added to support parenthesis to do "implicit" parenthesis so that you can do priorities correctly.

--
Mats