There is a problem said:
Use an array of 20 integers: a) write a function that will ilitialize the array to the sequence of random numbers in between 1-99.
b)Allow the user to enter new values for specific locations (the program will only allow values in between 1-99 that are not already in the array).
This is what I did:
int loc, nval;
for (int i=0; i<20; i++)
data[i] = rand() % 100;
for (i=0; i<20; i++)
cout << data[i] << endl;
cout << "\n\nSpecify the location: ";
cin >> loc;
if (loc != -1)
cout << "\n\nEnter new value: ";
cin >> nval;
if (nval != data[i])
cout << "Location " << loc << " : " << data[loc]
<< "\t-->\t" << nval;
cout << "This value already exist!\a" << endl;
if (loc == -1)
} // endl while
cout << "\n\n\n";
} // end main
However, It didn't work for the second question. Plz tell me what i did wrong and what did i miss in that code. Thank you very much!
PS: I am interested in and learning C++ by reading books!