Tuesday, 10 September 2013

Why does my array store un-needed values

Why does my array store un-needed values

I am having an issue with my code - I am getting a run-time error. The
arrays are only supposed to store 5 values, but it actually stores more.
#include <iostream>
using namespace std;
int main()
{
const int num = 5;
string t[num], name;
int m[num], score;
for(int i=0; i < num; i++)
{
cout << "Enter the name for score # " << i+1 << " :";
cin >> name;
t[i] = name;
for(int j=i; j<= i ;j++)
{
cout << "Enter the score for score # " << j+1 << " :";
cin >> score;
m[j] = score;
}
}
for(int i=0; i < num; i++)
cout << m[i] << endl;
}

No comments:

Post a Comment