Tricky question, correcting an array

Hey guys..

I'm making this simple program to calculate correlation coefficient
I've a problem here:
when I enter values of array, I sometimes mis-type a number and I want to
re-enter it again to correct it, without having to start the program all over again.
here's the code, I hope someone can give me a clue
1
2
3
4
5
6
7
8
9
10
11
12
for(i=1;i<=n;++i)
{
cout<< "\nEnter X"<<i<<" : ";
cin>>x;
sx+=x;
sxx+=(x*x);
cout<<"\nEnter Y"<<i<<" : ";
cin>>y;
sy+=y;
syy+=(y*y);
sxy+=(x*y);
}
I would suggest a loop. After the user enters x and y, display the values, then ask if they are correct. If not, continue looping until the user says they are correct.
How would I ask if the value is correct or not?
could you give an example?
1
2
3
4
5
6
7
8
9
10
11
12
int x, y;
char ans;
do
{  cout >> "Enter x: ";
    cin >> x;
    cout << "Enter y: ";
    cin >> y;
    cout << "You entered: x=" << x << " y=" << y << endl;
    cout >> "Is that correct?";
    cin >> ans;
}
while (ans != 'y');


Thanks
Topic archived. No new replies allowed.