如果两个数字相差1,如何输出字符串 [英] How do I output a string out if two numbers differs by 1

查看:86
本文介绍了如果两个数字相差1,如何输出字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当input1和input2之间的差值小于0.1时,如何输出文本。

可以包括负双倍和正双倍吗?



  #include   < ;   iostream  >  
using namespace std;

int main()
{
double input1 = 0 00 ;
double input2 = 0 00 ;
bool input = true ;

cout<< 请输入第一个数字<<的std :: ENDL;
cin>> input1;
cout<< 请输入第二个数字<< std :: endl ;
cin>> input2;
double input_diff = input1-input2;
cout<< 输入差异为<< input_diff<< endl ;





我试图把它放在上面的代码之后,但它会产生错误。



  if (input_diff>  -   2 。< span class =code-digit> 0 &<  2  0 ) { //  这里有什么问题? 
x = ;
cout<< 两者之间的值几乎相等<< ENDL;

}
}

解决方案

你的&<是胡言乱语。试想一下:是否有这样的运营商?

条件可能是(input_diff> -2.0)& (input_diff< 2.0);如果在圆括号上需要任何表达。



你关于0.1和负面的问题只是一团糟;你写0.1然后2.0,依此类推。请自己解决。小学数学包含在计算的先决条件中,这是你需要知道的最小部分。



-SA

How can I output the text when the difference between input1 and input2 is less than 0.1.
Can it includes both negative double and positive double?

#include <iostream>
using namespace std;

int main()
{
double input1=0.00;
    double input2=0.00;
    bool input=true;

    cout<<"Please enter first number"<<std::endl;
    cin>>input1;
    cout<<"Please enter second number"<<std::endl;
    cin>>input2;
    double input_diff=input1-input2;
    cout<<"input difference is "<<input_diff<<endl;



I tried to put this after the code above, but it produces error.

    if (input_diff > -2.0 & < 2.0){      // What is wrong here?
        x=true;
        cout<<"The value between the two is almost equal"<<endl;

    }
}

解决方案

Your "& <" is gibberish. Just think about it: is there such operator?
The condition could be (input_diff > -2.0) & (input_diff < 2.0); and if requires any expression on round brackets.

Your questions about 0.1 and negative is just a mess; you write 0.1 and then 2.0, and so on. Please sort it out yourself. Mathematics for elementary school is included in prerequisites for computing, a really smallest part of what you need to know.

—SA


这篇关于如果两个数字相差1,如何输出字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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