hello.
I tried to make a simulator scientific calculator with scrolling screen.
after compiling with Code :: blocks, I get the following error which does not know the meaning.
thanks in advance
/* simulator scientific calculator with scrolling screen;
the program performs the arithmetic operations, according to the priorities
arithmetic*/
#include <iostream>
usingnamespace std;
constint n_op =100;
struct oper
{
float a; // number
char sign; // detector of the arithmetic operator
int prior; // variable for the allocation of priorities, in arithmetic operations
};
struct oper calc[n_op];
int main()
{
int conta = 0; // counter elements and arithmetic inserted
float result = 0;
calc[0].prior = 3;
calc[0].a = 0;
cout<<" start \n: "<<result<<'\n';
while (cin.peek() != '\n')
{
conta++;
cin>>calc[conta].a>>calc[conta].sign;
}
for (int i=1; i<conta; i++) // Key priority than the arithmetic operator
{
switch (calc[i].sign)
{
case'*':
calc[i].prior = 1;
break;
case'/':
calc[i].prior = 2;
break;
case'+':
calc[i].prior = 3;
break;
case'-':
calc[i].prior = 4;
break;
case'=':
calc[i].prior = 5;
break;
default:
calc[i].prior = 5;
break;
}
cout<<" ";
}
for (int i=1; i<conta; i++) // cycle for the partial execution, of the arithmetic expression
{
switch (calc[i].prior)
{
case 1:
calc[i+1].a *= calc[i].a;
calc[i].prior = calc[i-1].prior;
if(calc[i].prior == 4)
{
calc[i+1].a *= (-1);
}
calc[i].a = 0;
break;
case 2:
if(calc[i+1].a != 0)
{
calc[i+1].a = calc[i].a / calc[i+1].a;
calc[i].prior = calc[i-1].prior;
if(calc[i].prior == 4)
{
calc[i+1].a *= (-1);
}
calc[i].a = 0;
}
else
{
cout<<" error imput value. \n division for 0. \n programm terminated \n";
return 0;
}
break;
case 3:
break;
case 4:
calc[i].a *= (-1);
break;
default:
break;
}
}
// cycle for the calculation of the sum of the partial operations
float r=0;
for (int i=1;i<=conta;i++)
{
r+=calc[i].a;
}
cout<<" the result is: "<<r<<endl;
return 0;
}
c:\programmi\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\libmingw32.a(main.o):main.c:(.text.startup+0xa7)||undefined reference to `WinMain@16'|
this code compiled correctly on VS2010, if it still doesn't compile on yours, maybe it's a compiler issue, though unlikely to not compile (it's just standard code).
c:\programmi\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\libmingw32.a(main.o):main.c:(.text.startup+0xa7)||undefined reference to `WinMain@16'|
The reference to WinMain suggests that this was set up as a Windows application. It should be a plain console application. That is, the choice of project type may be the problem.