Why last for cicle didn't in the output ???

#include <iostream>
#include <string>

using namespace std;

int n[12];
int p;
int r;
int main()
{
cout << "Will introduce twelve real numbers for array.\n";

for(p=0;p<=11;p++)
{
cout << "Introduce real numbers for array:\n";
cin >> n[p];
}
cout << "Introduce real number:\n";
cin >> r;

for(p=0;p<=11;p++)
{
if(n[p] < p)
{
cout << " The number " << n[p] << " is less than " << r ;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
You are comparing n[p] with p but in the message you wrote that n[p] is less than r

I think that instead of

1
2
3
4
if(n[p] < p)
 {
 cout << " The number " << n[p] << " is less than " << r ;
 }

the following code shall be

1
2
3
4
if(n[p] < r)
 {
 cout << " The number " << n[p] << " is less than " << r ;
 }
Omg, thank you a lot !
Topic archived. No new replies allowed.