How to capture command line information

Asked

Viewed 42 times

1

How do I, when typing a character, read the next one without the loop continuing until the iteration count is complete? Follow code below.

#include <iostream>
using namespace std;

int main(){

    int aluno;
    float a,b,c,d,p;

for(int n=1; n<=5000; n++){

    cout<<"Digite o nome do aluno"<<endl;
    cin>>aluno;
    cout<<"Digite a nota do primeiro bimestre"<<endl;
    cin>>a;
    cout<<"Digite a nota do segundo bimestre"<<endl;
    cin>>b;
    cout<<"Digite a nota do terceiro bimestre"<<endl;
    cin>>c;
    cout<<"Digite a nota do quarto bimestre"<<endl;
    cin>>d;

    p=(a+b+c+d)/3;

    if(p>=6){
        cout<<"O aluno "<<aluno<<" foi aprovado, a media dele corresponde a  "<<p<<endl;
    }

    else{
        cout<<"O aluno "<<aluno<<" foi reprovado, a media dele corresponde a "<<p<<endl;
    }

    cout<<"..........................................................."<<endl;
}

    return 0;
}

1 answer

4


Two things:

  • for(int n=1; n<=5000; n++) this will be repeated 5000 times. I think it is too much repetition to keep entering data on the keyboard until finished
  • You declared student whole (int aluno;). The correct would be to declare it as a string, ie change the statement to std::string aluno;
  • Thanks brother!!!! Helped me a lot! Thank you so much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.