assertion failure

Feb 7, 2013 at 1:37pm
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
# include <iostream>
using namespace std;
# include <cstring>
# include <string>
# include <xstring>
using namespace std;
int main()
{
string cometname;
long totalc=1;
cin>>cometname;
for (int i=1;i<=7;i++)
{
	if ((int ) cometname[i]>=65)
	if ((int ) cometname[i]<=90)
	totalc*=((int ) cometname[i]-64);

}

string groupname;
long totalg=1;
cin>>groupname;
for (int x=1;x<=6;x++)
{
	if ((int ) groupname[x]>=65)
	if ((int ) groupname[x]<=90)
	totalg=totalg*((int ) groupname[x]-64);

}
if(totalg%47==totalc%47)
	cout<<"GO"<<endl;
else
	cout<<"STAY"<<endl;
}

when i debug this program it says assertion failed,
what is that and how could i fix it? thank you.
Feb 7, 2013 at 2:08pm
In the first for loop, what do you think happens when cometname has a size of 4? (or anything less than 7)

Same possible problem below with groupname
Feb 7, 2013 at 3:24pm
oh ok thanks very much, but you didnt tell me what is assertion failure
Feb 7, 2013 at 3:31pm
An assertion failure is when the program fails a tst to assert that it is functioning properly.

In your case, accessing an index that is out of bounds fails the test that the index must be in bounds. This check is only in debug mode because it would cause slowdown in release.
Feb 7, 2013 at 3:42pm
ok thank you very much,any ideas how to solve it?
Feb 7, 2013 at 3:46pm
Use the .length() function on the strings rather than assuming that 7 and 6 are the correct sizes.
Feb 7, 2013 at 4:05pm
ok, i understand now.thanks,and sorry for disturbance
Topic archived. No new replies allowed.