作者ichen0128 (真想聊聊天)
看板C_and_CPP
標題Re: [問題] 分數範圍的問題 ???
時間Mon Feb 9 23:48:01 2009
#include <iostream>
using namespace std ;
int main()
{
int a,b,c,d ;
start: cout << "國文分數:" ;
cin >> a ;
cout << "英文分數:" ;
cin >> b ;
cout << "數學分數:" ;
cin >> c ;
{ while((a>100)||(b>100) ||(c>100)) ;
cout << "輸入分數範圍錯誤" ;
goto start ; }
d=a* 0.2 + b* 0.4 +c*0.4 ;
cout << "加權分數" << d << endl ;
system ("pause") ;
return 0 ;
}
這是我更改過的code 我要的程式 是能判讀錯誤的數值
也就是 a b 或c其中一個值大於100的時候
可以顯示 輸入分數的範圍錯誤 然後跳入重新輸入 新的數值
可是現在不管輸入的數值對或錯 都會顯示 輸入分數的範圍錯誤
請問要如何修改 ???
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.165.136.193
1F:推 fjm31714:我指while不是放在那裏是包含cin 02/09 23:58
2F:→ ichen0128:結果已經出來了 感謝指導 02/10 00:04
3F:推 disjoint126:while的語法建議再多看看兩題範例 02/10 09:58
4F:→ disjoint126:另外想熟練迴圈的話 盡量別使用goto~~ 02/10 09:59