Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
C++
#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..
Posted
Updated 8-Dec-12 9:26am
v2
Comments
CHill60 8-Dec-12 15:07pm    
Name missing after the "#include" ??

1 solution

Quote:
chmod +x Calculator.cpp

You should issue:
chmod +x Calculator 
instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900