I have a c++ code below that takes a string as input and outputs it n times. The while loop is functioning one less than expected:
For eg if I input n=1, the loop does not function
For n=2, the loop functions 1 time and so on:
Can anyone explain the error in logic.
int main(){
int n;
string line;
cin>>n;
while(n){
getline(cin,line);
cout<<line<<"\n";
n--;
}
}
Thanks in advance