工程與科技
大學
已解決

想請問專家 為什麼我先輸入0到100區間的分數都無法產生結果 

【問題】C++程式碼問題要先輸入0<或>100讓他出跑出請在次輸入成績的程序 能否有專家能提點 dev c++

#include <iostream>

#include <cstdlib>

using namespace std;

int main(void)

{

int score;

cout <<"請輸入成績";

cin >>score;

do{

   if((score<0)||(score>100))

  cout<<"成績輸入錯誤!請再輸入一次"<<endl;

  cin>>score;

      } while((score<0)||(score>100));

      

   

if((score>=80)&&(score<=100))

  cout<<"成績優異!"<<endl;

if((score>=60)&&(score<80))

  cout<<"成績尚可!"<<endl;

if((score>=0)&&(score<60))

  cout <<"成績不及格!"<<endl;

system("pause");

return 0;

}

c++程式碼

解答

✨ 最佳解答 ✨

你do-while裡面的if要把cout跟cin用{}括起來 否則程式在跑的時候會要你再輸入一次

留言
PromotionBanner
您的問題解決了嗎?