Here is my code:
Code:
//calc.h
#include <iostream>
#include <cmath>
using namespace std;
inline void operations()
{
cout<<"x,/,+,-,^,s2(square root)\n";
}
float math()
{
float x;
float y;
char a;
float answer;
cout<<"enter an problem (4o for operations)";
cin>> x >> a >> y;
switch (a){
case 'o':
answer = (char) 0;
operations();
break;
case 's':
answer = sqrt (x);
break;
case 'x':
answer = x*y;
break;
case '/':
answer = x/y;
break;
case '+':
answer = x+y;
break;
case '-':
answer = x-y;
break;
case '^':
answer = pow (x,y);
break;
}
return answer;
}
Code:
//calculator test.cpp
#include <iostream>
#include <dos.h>
#include "calc.h"
using namespace std;
int main()
{
float answer = math();
cout<< answer <<"\n";
system("pause");
}
I have two problems:
1)I have to type 4o twice for t to show the operations.
2)I don't want to have to press 4 (well any other number) for it to show the operations.