String Problem

Hey guys, I was wondering if you could help me out with this problem on my program. I ask the user to guess a letter. If the letter is not found in the string , i tell them that it's wrong. But that does not work the program stops and gives me a "debug assertion failed " error. Can somebody tell me how to fix this.
Thanks.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>
#include <fstream>
using namespace std;


string name="hello";
char letter;
int i;
string store[100];
int main ()
{
	
	cout<"enter a letter : ";
	cin>>letter;

	for ( i = 0; i  < name.length(); i++ )
	{


		store[i] = name[i];

	}

	if( letter != name[i] )
	{
		cout<<"wrong"<<endl;

	}



system("PAUSE");
return 0;



}
Last edited on
oops for line 14
I forgot to put another "<" but that is not the probelm.
On line 25 you're accessing out of bounds on your name array.
how do I fix it, if I put it in the for loop it will print "wrong" many times as the length of the string.
Topic archived. No new replies allowed.