※ 引述《adihuang (楓所愛的秋)》之銘言:
: ※ 引述《mapleden (il'est fou)》之銘言:
: : #include <iostream>
: : #include <stdio.h>
: : using std::cin;
: : using std::cout;
: : using std::endl;
: : int main()
: : {
: : int a,b,c,Large,Small;
; ; cout << "Please type in 3 different numbers\n";
: : cin >> a >> b >> c;
: : Large=b;
: : Small=a;
: : if (a>b)
{ Large=a;
: : Small=b;
: : ~~~~~~~~~~~~~~~~~~~~~~~~~~我在這邊加一ㄍif(a<b)
: large=b
: small=a}
: 就不會有四比三大的情形了~~只是
: 不能用else~不知道為什麼
: if (c<Small)
: : Small=c;
: : if (c>Large)
{ Large=c;
: : cout << "Sum is " << a+b+c << endl;
: : cout << "Mean = " << (a+b+c)/3 << endl;
: : cout << "Product is " << a*b*c << endl;
: : cout << "Largest is " << Large << endl;
: : cout << "Smallest is " << Small << endl;
: : system ("PAUSE");
: : return 0:
}
; ; }
: : 你們試著輸入3;5;4
: : 結果會變得很奇怪
: : smallest會是4
就差這兩對大括號,if後就只行一句
if .. else 我在c++中還未接觸過,但在pascal中,
if ...
then ... else ...;
只算一句,若在 then ... 與 else 之間加個分號(即變為兩句),就會發生錯誤
不知你是否這個問題
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.239.182