Hi , I'm a beggginer in c++
and i didn't find what a problem from this
while (n[p] < r]
{
cout << " The number " << n[p] << " is less than " << r << endl;
}
please help me .
the full program is
#include <iostream>
#include <string>
using namespace std;
string n[12];
int p;
int r;
int main()
{
cout << "Will introduce twelve real elements:\n";
for(p=0;p<=11;p++)
{
cout << "Introducing twelve real numbers:\n";
cin >> n[p];
}
cout << "Introducing real number:\n";
cin >> r;
while (n[p] < r]
{
cout << " The number " << n[p] << " is less than " << r << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
You may not compare an object of type int with an object of type std::string
So this code
1 2 3 4
|
while (n[p] < r]
{
cout << " The number " << n[p] << " is less than " << r << endl;
}
|
is invalid. Moreover if this comparision would be allowed then the loop would be infinite if n[p] would be indeed less than r.
Last edited on
use int n[12] instead of string n[12]