I’ve just switched over from Borland to gcc/g++ to compile my C/C++ codes. I’m still learning some of the basics, but I’ve been getting an error, and I’m not able to get it working. The error is a classic “‘main’ must return ‘int'”.
I edited my code to return 0 at the last line, but it’s still throwing the error. I’ll put up an example from one of my early experiments (a calculator). Any help would be greatly appreciated–especially if you can explain why what I’m doing is erroring.
[code]
#include
#include
int main()
{
float num1;
float num2;
char op;
float ans;
cout << "Please Enter A Number: ";
cin >> num1;
cout << "Please Enter Another Number: ";
cin >> num2;
cout << "Press A to add the two numbers."
<< endl
<< "Press S to subtract the two numbers."
<< endl
<< "Press M to multiply the two numbers."
<< endl
<< "Press D to divide the two numbers."
<< endl;
cin >> op;
if (op == 65 || op == 97)
{
ans = num1 + num2;
cout << "The answer is " << ans << endl;
}
if (op == 83 || op == 115)
{
ans = num1 - num2;
cout << "The answer is " << ans << endl;
}
if (op == 77 || op == 109)
{
ans = num1 * num2;
cout << "The answer is " << ans << endl;
}
if (op == 68 || op == 100)
{
ans = num1 / num2;
cout << "The answer is " << ans << endl;
}
if (op != 65 && op !=83 && op !=77 && op !=68 && op !=97 && op !=115 && op !=109 && op !=100, 0)
{
cout << "No valid operation was chosen!" << endl;
}
{
system("pause");
}
return 0;
}
[\code]