Following is my calculator program but i have two errors reported by my IDE
1)Error 1: error C3861: 'confir_mation': identifier not found c:\users\abhinav\documents\visual studio 2010\abhinav_examples
2)Error 2: error C3861: 'main': identifier not found
I'm new to c++ programming, any help is much appreciated!
//program:
#include "stdafx.h"
#include <iostream>
using namespace std;
double a,b,c;
int y;
int operation()
{
cout << "Please choose a mathematical operand from following available: \n '1' to divide \n '2' to multiply \n '3' to add \n '4' to subtract\n";
cin >> c;
if ( c==1 )
{
cout << "The result is: " << (a/b);
}
else if ( c==2 )
{
cout << "The result is: " << (a*b);
}
else if ( c==3 )
{
cout << "The result is: " << (a+b);
}
else if ( c==4 )
{
cout << "The result is: " << (a-b);
}
else
{
cout << "Don't be stupid!!! Try Again...";
cout << "\n\n\n" ;
cout << operation();
}
cout << confir_mation();
}
int confir_mation()
{
cout << "Want to calculate more?? \n"
<< "Enter '0' for a 'Yes' and '1' to 'Termiate':\n";
cin >> y;
cout << "\n\n\n";
if( y==0 )
{
cout << "Welcome again...";
return main();
}
else if( y==1)
{
cout << "Leaving so soon!\n\n";
return 0;
}
else
{
cout << "Don't be a jerk! Enter a valid input! \n\n\n";
cout << confir_mation();
}
return 0;
}
int main()
{
cout << "Enter first number to be evaluated: \n";
cin >> a;
cout << "You entered: " << a;
cout << "\n\n\n";
You cannot call main().
The reason for "identifier not found" messages here is that the name is used before it has been declared. The general solution is to declare function prototypes at the top of the code. Then the functions themselves can be placed in any order. I prefer to put function main() first.
The program needs to use some sort of loops to control the processing.