P
papoupapa
Hi
I reay think // A should be (nbr_entry != 0) || (i < NMAX) instead
of (nbr_entry != 0) && (i < NMAX)
As it's working, to my understanding, the second body of the for loop
is being read from the left to the right.
int main()
{
const int NMAX = 5 ;
vector<int>Numbers(NMAX) ;
int nbr_entry = 1 ;
int i, j ;
cout << "\nThis program reads a sequence of numbers \n" ;
j = 0 ;
nbr_entry = 1 ;
for (i = 0 ; (nbr_entry != 0) && (i < NMAX) ; i++, j++) // A
{
cout << "\nValue " << i+1 << " : " ;
cin >> nbr_entry ;
Numbers = nbr_entry ;
}
cout << "\n\nNumbers entered : \n" ;
for (i = 0 ; i < j ; i++)
cout << "Value " << i+1 << ": " << Numbers << "\n" ;
cout << "\n\n" ;
system("pause") ;
return 0 ;
}
I reay think // A should be (nbr_entry != 0) || (i < NMAX) instead
of (nbr_entry != 0) && (i < NMAX)
As it's working, to my understanding, the second body of the for loop
is being read from the left to the right.
int main()
{
const int NMAX = 5 ;
vector<int>Numbers(NMAX) ;
int nbr_entry = 1 ;
int i, j ;
cout << "\nThis program reads a sequence of numbers \n" ;
j = 0 ;
nbr_entry = 1 ;
for (i = 0 ; (nbr_entry != 0) && (i < NMAX) ; i++, j++) // A
{
cout << "\nValue " << i+1 << " : " ;
cin >> nbr_entry ;
Numbers = nbr_entry ;
}
cout << "\n\nNumbers entered : \n" ;
for (i = 0 ; i < j ; i++)
cout << "Value " << i+1 << ": " << Numbers << "\n" ;
cout << "\n\n" ;
system("pause") ;
return 0 ;
}