I am having a little problem with this code. it is a C++ code and i want to run it in Ubuntu. I have used this code:
#include<stdio.h>
int main()
{
int n1,n2,n3;
char sym;
printf("Welcome to my Calculator\n\n");
printf("Enter the 1st number then the operation you want to perform and then the 2nd number");
scanf("%f%c%f",&n1,&sym,&n2);
if(sym=='+')
{
n3=n1+n2;
printf("\n%f",n3);
}
if(sym=='-')
{
n3=n1-n2;
printf("\n%f",n3);
}
if(sym=='*')
{
n3=n1*n2;
printf("\n%f",n3);
}
if(sym=='/')
{
n3=n1/n2;
printf("\n%f",n3);
}
}
I have compiled it by using this command in the terminal:
g++ -Wall -W -Werror Calculator.cpp -o Calculator
and it compiled perfectly. After this I made an executable file of this program by using:
chmod +x Calculator.cpp
it also worked, but after this when I executed my program by this command: ./Calculator
it gave and error:
line 3: syntax error near unexpected token `('
line 3: `int main()'
i can't understand what is the problem please help..