通過「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){...}'用於條件分支。 –