hey,
ive just started programming in c++, please go easy on me. ive tried to write a short calculator program, its just a simple console program, but im getting this error.
im compiling with borland 5.5 using "bcc32 calc.cpp"
#include <iostream>
using namespace std;
void add(float a, b) {
float c = a + b;
cout << c << endl;
}
void subtract(float a, b) {
float c = a - b;
cout << c << endl;
}
void multiply(float a, b) {
float c = a * b;
cout << c << endl;
}
void divide(float a, b) {
float c = a / b;
cout << c << endl;
}
int main() {
char x;
float a, b;
cout << "shaun's calculator v0.1\n";
cout << "please enter the first number\n";
cin >> a;
cout << "please enter the second number\n";
cin >> b;
cout << "+\n";
cout << "-\n";
cout << "*\n";
cout << "/\n";
cin >> x;
if(x = +)
add(a, b)
if(x = -)
subtract(a, b)
if(x = *)
multiply(a, b)
if(x = /)
divide(a, b)
return 0;
}
the error i get this error:
Error E2303 calc.cpp 5: Type name expected
*** 1 errors in Compile ***
what wrong with this code?
ive just started programming in c++, please go easy on me. ive tried to write a short calculator program, its just a simple console program, but im getting this error.
im compiling with borland 5.5 using "bcc32 calc.cpp"
#include <iostream>
using namespace std;
void add(float a, b) {
float c = a + b;
cout << c << endl;
}
void subtract(float a, b) {
float c = a - b;
cout << c << endl;
}
void multiply(float a, b) {
float c = a * b;
cout << c << endl;
}
void divide(float a, b) {
float c = a / b;
cout << c << endl;
}
int main() {
char x;
float a, b;
cout << "shaun's calculator v0.1\n";
cout << "please enter the first number\n";
cin >> a;
cout << "please enter the second number\n";
cin >> b;
cout << "+\n";
cout << "-\n";
cout << "*\n";
cout << "/\n";
cin >> x;
if(x = +)
add(a, b)
if(x = -)
subtract(a, b)
if(x = *)
multiply(a, b)
if(x = /)
divide(a, b)
return 0;
}
the error i get this error:
Error E2303 calc.cpp 5: Type name expected
*** 1 errors in Compile ***
what wrong with this code?