C ++中的计算器代码问题 [英] Problem with Code for a Calculator in C++

查看:207
本文介绍了C ++中的计算器代码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此代码有点问题。它是一个C ++代码,我想在Ubuntu中运行它。我使用过这段代码:

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); 
    } 
}



我在终端中使用此命令编译了它:

g ++ -Wall -W -Werror Calculator.cpp -o计算器

并且它编译得很完美。在此之后,我使用以下方法制作了该程序的可执行文件:

chmod + x Calculator.cpp

它也有效,但在此之后我通过此命令执行程序:./计算器

它给出了错误:

第3行:意外令牌附近的语法错误`(''

第3行:`int main()''



i无法理解有什么问题请帮助..


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..

推荐答案

Quote:

chmod + x Calculator .cpp

chmod +x Calculator.cpp



你应该问题:


You should issue:

chmod +x Calculator 

代替。


这篇关于C ++中的计算器代码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆