Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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++ 如何做比率';s,大于或小于C++;_C++ - Fatal编程技术网

C++ 如何做比率';s,大于或小于C++;

C++ 如何做比率';s,大于或小于C++;,c++,C++,我是从“C++编程与原理”中编写这个程序的,我需要编写一个程序,这个程序需要太多的整数,求和、差、大于和小于值以及比率 由于某种原因,我不能在工作中得到更多和更少。它实际上并不执行该功能。它只是简单地打印数字,即:4将小于2 我的第二个问题是,我如何写出一个方程来计算比率 #include <iostream> #include <string> #include <vector> #include <algorithm> #include <

我是从“C++编程与原理”中编写这个程序的,我需要编写一个程序,这个程序需要太多的整数,求和、差、大于和小于值以及比率

由于某种原因,我不能在工作中得到更多和更少。它实际上并不执行该功能。它只是简单地打印数字,即:4将小于2

我的第二个问题是,我如何写出一个方程来计算比率

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open() {char ch;cin>>ch;}
int main()
{
    int a;
    int b;
    cout<<"Enter two values.\n";
    cin>>a; cin>>b;
    if (a > b);cout<< a << " Is greater than " << b << "\n";
    if(a < b);cout<< a << " Is less than " << b << "\n";
    cout<<a << " plus " << b << " is " << a+b << "\n"; 
    cout<<a << " minus " << b << " is " << a-b << "\n";
    keep_window_open();
    return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
内联void保持窗口打开({char ch;cin>>ch;}
int main()
{
INTA;
int b;
couta;cin>>b;

如果(a>b);cout首先,您需要移除if(a>b)和if(a 我建议找出a和b之间的最大公因数,然后执行以下命令:


cout我认为下面的代码片段回答了您所有的问题

#include<iostream.h>

void main()
  {
  float a,b;
  cout<<"Enter 2 numbers";
  cin>>a>>b;

  cout<<"Plus = "<<(a+b)<<"\n";
  cout<<"Minus = "<<(a-b)<<"\n";
  cout<<"Greater = "<<((a>b)?a:b)<<"\n";
  cout<<"Smaller = "<<((a<b)?a:b)<<"\n";
  cout<<"Ratio = 1:"<<(1/(((a<b)?a:b)/((a>b)?a:b)));
  }
#包括
void main()
{
浮子a、b;
couta>>b;

cout问题不在于具体的运算符,而在于它们包含在什么上下文中。在if条件后删除分号在if(a>b)后删除分号;以及if(a+1。对于刚开始使用的人来说,找出GCD算法并实现它是一项有趣的小任务:)我为什么要使用欧几里德算法,而我只能使用“float”代替“int”和“cout>>(a/b)"如果您使用浮点而不是int,那么对于a=14和b=4这样的情况,您的输出将为3.5。我假设您希望将比率打印为7:2,如果是这样,那么使用欧几里德算法是您的最佳选择。这是逻辑。如果您希望在用户输入a=18和b=5这样的情况下使用非十进制值,请修改t他相应地修改了源代码。这里的结果是1:3.6,这本身就是正确的。