program stopped working with random signs in output

I wrote this program to generate random names from given array, on first attempt it ran very well, but after compiling 2 or 3 times, a beep sound started coming from my laptop and program stopped working.
also I saw some weird numbers and signs in output window, anybody know what could have gone wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #include <iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
using namespace std;

int main()
{
    srand((int)time(0));
    int r,s=0;
    string a[10]={"kumar","Shital","renu","Renuka","Kshitija","stacy","Pradnya","Smita","Manasi","Teja"};
    while(s++<10)
    {
        int r=(rand()%10)+1;
        cout<<a[r]<<'\t';
    }


    return 0;
}
I see that r can take any value from 1 to 10. Shouldn't it be any value from 0 to 9 ?
Last edited on
Topic archived. No new replies allowed.