Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用getche()时在输出中获取错误的ans_C++ - Fatal编程技术网

C++ 使用getche()时在输出中获取错误的ans

C++ 使用getche()时在输出中获取错误的ans,c++,C++,这是我的密码 #include<iostream>//Per processor directive #include<conio.h> //For getche() using namespace std; int main() { int no,no2,no3,no4; cout<<"Enter no\n"; no=getche(); cout<<"+"; no2=get

这是我的密码

#include<iostream>//Per processor directive
#include<conio.h>                      //For getche()
using namespace std;

int main()
{
   int no,no2,no3,no4;
   cout<<"Enter no\n";
   no=getche();
   cout<<"+";
   no2=getche();
   no3=no+no2;
   cout<<"\nAns "<<no3;


   return 0;


}
 //output 
Enter no
5+5
Ans is 106
为什么我的分数是106而不是10 任何帮助都将不胜感激

Enter no
5+5
Ans is 106
  • 似乎
    getche()
    已经从输入中减去了48。两个空格产生结果-112,即
    ((32-48)-48)+((32-48)-48)
    ,因此您总是减去96太多

  • Enter no
    5+5
    Ans is 106
    
    <> L> >GETCH()/<代码>,在VisualC++ 2013中,您的代码甚至没有编译警告,并且由于您使用的是<代码> IoSoS和 STD::CUT无论如何,为什么不继续使用<代码> STD::CIN < /C> >

    Enter no
    5+5
    Ans is 106
    
    编辑: 使用
    \u getche()
    代码可以正常工作。我不知道为什么。请改用类似于
    std::cin
    的东西,
    getche()
    已经过时了

    Enter no
    5+5
    Ans is 106
    
    #include <iostream>
    
    int main( )
    {
        int Input_1;
        int Input_2;
        int Result;
        std::cout << "Your addition: \n";
        std::cin >> Input_1;
    
        std::cout << "+ \n";
        std::cin >> Input_2;
    
        Result = Input_1 + Input_2;
        std::cout << "\n" << "Result: " << Result;
    
        //Keep the window open
        getchar( );
        getchar( );
        return 0;
    }
    
    #包括
    int main()
    {
    int输入_1;
    int输入_2;
    int结果;
    标准::cout>Input_1;
    标准::cout>Input_2;
    结果=输入_1+输入_2;
    
    std::coutgetche()用于接受字符作为输入。如果输入5,则ASCII值为“5”是53,所以答案是106。

    你们必须减去96两次……为什么我要减去96两次1995年的数字。它想把它的
    conio.h
    拿回来。但是ASCII
    0
    是十进制48,所以为什么要减去96两次呢?谢谢大家给我这个主意,因为我的输入不是整数,而是ASCII值,53代表5,这就是5+5=53+53实际上,输入行中应该出现的+符号受到此干扰
    Enter no
    5+5
    Ans is 106