0
#include <iostream>
using namespace std;

int main() {
   int test_cases;cin>>test_cases;  // 1st input

   while(t--)
   {
    string input;
    getline(cin,input);   //2nd input
    cout<<"hello";
   }
    return 0;
}

when user enter 1...this program only print "hello" and stops it doesn't ask for another input. when user enter an value greater than 1, then this program executes for 1 times less than what user have entered. i don't know why this is happening!

  • 1
    TL;DR of the dupe: You need to remove the newline `cin>>test_cases;` leaves in the buffer. To do that add `cin.ignore()` after `cin>>test_cases;`. – NathanOliver Jan 02 '20 at 15:01
  • ?? variable t seems not to be defined at all. Or do you mean test_cases? – A M Jan 02 '20 at 15:46

0 Answers0