Trending News
c++的程式if 及 if-else 語句
if 及 if-else 語句
#include <iostream.h>
main()
{
int x, y, min;
cout << "Enter x: ";
cin >> x;
cout << "Enter y: ";
cin >> y;
if (x < y)
min = x;
else
min = y;
cout << x;
if (x > y)
cout << " > ";
else
cout << " <= ";
cout << y << endl;
cout << min << " is the smaller number." << endl;
return 0;
}
我想讓他在執行的時候 停在執行結果上...該如何改ㄋ 請大大幫忙
還是不型
檔案類型]C++ Source File
Dev-C++ 4
您有信箱或及時通ㄇ??
還是有讀到一個錯誤...還是我把檔案給你 妳幫我改看看
taco2017@yahoo.com.tw
即時通也事
2 Answers
- 1 decade agoFavorite Answer
你是用dev-c++麼?
dev-c++的話,加上system("PAUSE");
就OK了,
或者用
#include <cstdio>
getchar();
2008-04-29 16:45:32 補充:
getchar();
加在最後return 0;的上面一行。
2008-04-30 12:14:28 補充:
#include
main()
{
int x, y, min;
cout << "Enter x: ";
cin >> x;
cout << "Enter y: ";
cin >> y;
if (x < y)
min = x;
else
min = y;
cout << x;
if (x > y)
cout << " > ";
else
cout << " <= ";
cout << y << endl;
cout << min << " is the smaller number." << endl;
system("PAUSE");
return 0;
}
2008-04-30 20:18:52 補充:
//第一行改為
#include
2008-04-30 20:19:45 補充:
//第一行是
#include "iostream.h"
2008-04-30 20:26:01 補充:
我試過了,可以啊!
妳把e-mail或MSN給我,我把檔案給妳好了。
2008-05-01 08:57:54 補充:
我用e-mail寄給你了,
code改寫成比較formal,
所以跟另一位回答者比較像,
不過我之前試過,用我知識+上的回答也是可以的。
Source(s): me, 測試環境Dev-C++ 4.9.9.2, 其它如上, 其它如上, 測試環境Dev-C++ 4.9.9.2 - 1 decade ago
註:<>請自行改為半形
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int x, y, min;
cout << "Enter x: ";
cin >> x;
cout << "Enter y: ";
cin >> y;
if (x < y)
min = x;
else
min = y;
cout << x;
if (x > y)
cout << " > ";
else
cout << " <= ";
cout << y << endl;
cout << min << " is the smaller number." << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
這樣子就行了
建議你寫程式時
從
檔案->開新專案->專案->Console Applic ation
建立專案
這樣一些基本的東西它都幫你打好了
然後主程式寫在
int main(int argc, char *argv[])
{
的下面
Function寫在int main上面
如果有用到較特殊的運算式
例如: sqrt(n)--根號
可以在最上面加上
#include <cmath>(<>改成半形)
等等等....
如果你的Dev C 是英文的
可以選
Tools->Environment Options->Interface->Language->Chinese[TW]
就變成中文了
Source(s): myself