# Thread: You think this is worthy of sending into the website to be posted?

1. ## You think this is worthy of sending into the website to be posted?

I know this is a simple program, but I like the idea of what it does and I remember when I first started programming, it's one of the things I really wanted to make.

It's a simple calculator that accepts an undetermined amount of input.

Code:
```#include <iostream>

using namespace std;

int main() {
double numInput[100];
char signInput[100];
int x = 0;

cout << "Type a standard mathematical operation ending with equals: " << endl
<< "ex. 5 + 5 =" << endl;

cin >> numInput[0];
cin >> signInput[0];

do {
x++;
cin >> numInput[x];
cin >> signInput[x];
} while (signInput[x] != '=');

for (int y = 0; y <= x; y++) {
switch (signInput[y]) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
break;
}
}

return 0;
}```
What do ya think? If you can think of ways of improving it, please say. I love critiques.

2. I like the concept. I would put in an order of operations now. For example:
5+2+3*5/6=

It will do 3*5 then divide that result by 6, then add the remaining values. Maybe even put in a function to balance single variable equations after that. Then throw in more operators like sin, cos, tan, arccos, arctan, powers, etc. Good work.

3. nice work dude but here's what else u can do:
-after displaying the result make it ask u again if u would like to do another calculation or if u would like to quit. here's some code extracted from one of my projects:

Code:
```int again()
{
int option;
cout << "again? (1 = yes, 2 = no)  ";
cin >> option;
switch (option)
{
case 1:
dreptunghi();
break;
case 2:
return 0;
break;
default:
cout << "introduce un raspuns valid! \n";
again();

}
return 0;
}```

4. Yeah, order of operations seems like a good idea. I'll also add some more functions, I would have to change the code a bit since it couldn't just read number, sign, number, sign... but it's no problem and it's another good thing to show in the program. I'm also considering the abilty to use an "ans" arguement to append the last equation.

I'm glad that you see potential, thanks for the reply. I'll spruce it up a bit, make it more interesting.

EDIT: Here is a little Order of Operations logic. It works fine, it just looks a bit screwy, what do you think?
Code:
```   if (signInput[0] != '*' && signInput[0] != '/')

for (int y = 0; y <= x; y++) {
switch (signInput[y]) {
case '*':
numInput[y+1] *= numInput[y];
signInput[y] = '+';
numInput[y] = 0;
break;
case '/':
numInput[y+1] = numInput[y] / numInput[y+1];
signInput[y] = '+';
numInput[y] = 0;
break;
}
}
for (int y = 0; y <= x; y++) {
switch (signInput[y]) {
case '+':
break;
case '-':
break;
}
}```

5. Since this is a pretty basic program, why not try to demonstrate some of the basic rules:

Code:
```double numInput[100] = {0};
char signInput[100] = {0};
2) Use read statements in a loop conditional. If there are any stream errors, the loop will terminate and not vainly try to read in more data or enter into an infinite loop. Your program can enter into an infinite loop if a stream error occurs while reading the data.

You could actually do this:
Code:
`for(int x = 0; (cin>>numInput[x]>>signInput[x]) && (signInput[x] != '='); ++x)`
but you might want to opt for the more readable:
Code:
```int x = 0;
while( cin>>numInput[x]>>signInput[x]  && signInput[x] != '=' )
{
++x;
}```
or,
Code:
```int x = 0;
while( cin>>numInput[x]>>signInput[x] )
{
if(signInput[x] == '=')
break;

++x;
}```