通过“C++编程语言”进行阅读,我目前的任务是编写一个程序,其中包含两个变量并确定最小,最大,总和,差异,乘积和比率的价值。如何在执行方程时使用C++开始换行
问题是我无法开始换行。 “\ n”不起作用,因为我在报价后有变量。和“< < endl < <”只适用于第一行。我把这个问题搞糊涂了,我会尽快完成。
#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 value one\n";
cin>>a;
cout<<"Enter value two\n";
cin>>b;
(a>b); cout<< a << " Is greater than " << b;
(a<b); cout<< a << " Is less than " << b;
keep_window_open();
return 0;
}
注意''\ n“'和'std :: endl'之间的区别在于后者包含'flush';在这种情况下,这对你来说没有任何意义。 – Keith
你可以像你已经做的那样连锁'<<':if(a> b)cout << a <<“大于”<< b <<“\ n”;'。请注意'(a> b);'本身没有影响;它只是计算'a'是否大于'b'并且对结果不做任何事情。你希望'if(condition){...}'用于条件分支。 –