Hello everyone. I recently started using C++ and blah blah blah you know the rest.
Using my extremely limited knowledge, I attempted to make a basic 4 function calculator CUI in C++. The code I wrote is as follows.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
char operator -;
char operator +;
char operator *;
char operator /;
int myoperator;
float num1;
float num2;
float result;
int mainproc ()
{
cout << "Welcome to the 4-Basic-Calculator!\nEnter first number: ";
cin >> num1;
cout << "\nEnter the operator: ";
cin >> operator;
if(operator == "+")
myoperator = 1;
if(operator == "-")
myoperator = 2;
if(operator == "*")
myoperator = 3;
if(operator == "/")
myoperator = 4;
if(operator != "+" || "-" || "*" || "/")
{
cout << "You fail";
system("PING LOCALHOST -5 >nul");
return 0;
}
cout << "\nEnter second number: ";
cin >> num2;
if(myoperator == 1)
result = num1 + num2;
if(myoperator == 2)
result = num1 - num2;
if(myoperator == 3)
result = num1 * num2;
if(myoperator == 4)
result = num1 / num2;
cout << \nresult << "\nThank you for using the 4-Basic-Calculator coded by Gimper and Foteye! Coming soon - A repeat function!";
system("PAUSE");
return 0;
}
From what I can see it should work, but I keep getting these 2 build errors.
c:\documents and settings\luke\my documents\visual studio 2008\projects\calculator\calculator\calculator.cpp(20) : error C2833: 'operator ;' is not a recognized operator or type
and
c:\documents and settings\luke\my documents\visual studio 2008\projects\calculator\calculator\calculator.cpp(20) : error C2059: syntax error : 'newline'
Can someone please explain to me where I've gone wrong and how to fix it? And of course, if it isn't too much trouble, fix the code? Thanks in advance :)