I am making a (very) simple calculator program in C++ using Code::Blocks as my IDE. I am experiencing a couple of errors in my program. Please take a look at my code and tell me what the mistake is. Thank you.
#include <iostream>
#include <limits>
#include <conio.h>
int num1;
char Operator;
int num2;
void sum() {
std::cin >> num1; // User inputs first number
std::cin >> Operator; // User inputs operator
std::cin >> num2; // User inputs second number
// These if statements identify the operator and perform the appropriate
// operation
if ( Operator == '+' ) {
std::cout << num1 + num2;
}
else if ( Operator == '-' ) {
std::cout << num1 - num2;
}
else if ( Operator == '*' ) {
std::cout << num1 * num2;
}
else if ( Operator == '/' ) {
std::cout << num1 / num2;
}
else {
std:: cout << "Incorrect value/s entered.";
}
}
int main {
std::cout << "Press q to quit the program.";
while(1) {
sum()
if(ascii_value==113) { // For Q
break;
}
}
return 0;
}
Errors:
error: invalid user-defined conversion from 'std:: basic_ostream<char>' to
'int' [-fpermissive]
error: expected unqualified-id before 'while'
I started learning C++ just four days ago, so please appreciate the fact that I don't know much about the errors. Also, I am unsure whether i need to include limits, so please tell me in the comments below.
int main
is not a function declaration change it to
int main()
and sum()
needs a semicolon.
and in if(ascii_value==113)
, ascii_value
is defined nowhere in the code