Like this: (btw, thanks for the code. You really know your stuff)
Code:
#include <iostream>
using namespace std;
void add( float, float );
void sub( float, float );
void mult( float, float );
void divd( float, float );
int main()
{
cout << "Input two numbers and an operator ";
float a;
float b;
char oper;
cin >> a >> b >> oper;
switch( oper )
{
case '+':
add( a, b );
break;
case '-':
sub( a, b );
break;
case '*':
mult( a, b );
break;
case '/':
divd( a, b );
break;
default:
break;
}
return( 0 );
}
void add( float x, float y )
{
cout << "Answer: " << x + y << endl;
}
void sub( float x, float y )
{
cout << "Answer: " << x - y << endl;
}
void mult( float x, float y )
{
cout << "Answer: " << x * y << endl;
}
void divd( float x, float y )
{
if( y == 0 )
{
cout << "Can't divide by zero, setting denominator to 1" << endl;
y = 0;
}
cout << "Answer: " << x / y << endl;
}
Bookmarks