runtime error?

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
h_davary
New poster
Posts: 4
Joined: Tue May 15, 2007 8:29 am

runtime error?

Post by h_davary »

before i sent this code to online judge i had test it with dev4.9.9.2 and visual studio C++ 6.0 and worked well :D
but i dont know why it says it has "runtime error!" :
:roll:
------------------------------
Your program has died with signal 11 (SIGSEGV). Meaning:

Invalid memory reference


Before crash, it ran during 0.002 seconds.
-----------------------------


can anyone help me?
:cry:

Code: Select all

#include <iostream>
#include <string>
using namespace std;

double p[]={12.53,1.42,4.68,5.86,13.68,0.69,1.01,0.70,6.25,0.44,0.00,4.97,3.15,6.71,8.68,2.51,0.88,6.87,7.98,4.63,3.93,0.90,0.02,0.22,0.90,0.52};

double sbc(string w)
{
	int k;
double su=0;

	for (k=0;k<w.length();k++)
	{
		su += k*p[(int(w[k])-97)];

	}
	return su;
}

int main()
{
int i,l,k,m,n;
double j[100];

string str[100];
	cin >> i ;
	for (l=0;l<i;l++)
	{
		cin >> str[l];
		j[l]=sbc(str[l]);
		
	}
	for (l=0;l<i;l++) 
	{
	m = str[l].length();
	n=0;	
	double sum=0,av = 0;
		for (k=0;k<i;k++)
		{
			if (str[k].length() == m)
			{
				n +=1;
				sum += sbc(str[k]);
			}
		}
	av = sum / n;
	if (sbc(str[l]) < av) cout << "below"<< endl;
	else cout << "above or equal" << endl;
	}

	

return 0;

}

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: runtime error?

Post by lnr »

When you take a number as an input which greater than 102 then

cin >> i ;
for (l=0;l<i;l++)
{
cin >> str[l];
j[l]=sbc(str[l]);
}
But you declare array double j[100].
May be that's why runtime error.
Post Reply

Return to “C++”