web123456

[C++ gives a batch of percentage scores, requiring the output of corresponding score levels A, B, C, D, E]

  • //Method two while loop,else if
  • #include<iostream>
  • void pr(int n);
  • using namespace std;
  • int main(){
  • int n,i=0; //The value of i should be set to0
  • cin>>n;
  • while(n--){ //While(n--) execute steps:
  • //1.First take the value of n to determine whether it is0, if yes, jump out of the loop
  • //2.If not, execute n=n-1
  • //3. Then execute a while loop
  • int num;
  • cin>>num;
  • pr(num);
  • if(i!=n) cout<<" "; //The value of n is0
  • }
  • return 0;
  • }
  • void pr(int n){
  • if(n>=90) cout<<"A";
  • else if(n>=80) cout<<"B"; //else ifConditional sentences can eliminate the previous situation
  • else if(n>=70) cout<<"C";
  • else if(n>=60) cout<<"D";
  • else cout<<"E";
  • }