1 / 2
Jan 2012

will anybody tell me why this code is not running?

include

include

include

include

using namespace std;
int main()
{
char ch[1000],str[10],*pEnd;
long double d1,d2,d3=0,d4=0,d5;
int i=0;
string dummy;
getline(cin,dummy);
cin.getline(ch,999);
while(ch[i]!='\0')
{
while(ch[i]!='(')
i++;
int j=0;
while(ch[i]!=')')
{
str[j++]=ch[i++];
if(ch[i]==',')
i++;
}
d1=strtod(str,&pEnd);
d2=strtod(pEnd,NULL);
}

while(cin.getline(ch,999))
{
  int j=0;
 while(ch[i]!='\0')
 {
  while(ch[i]!='(')
     i++;
  while(ch[i]!=')')
  {
    str[j++]=ch[i++];
    if(ch[i]==',')
      i++;
  }
 d3=strtod(str,&pEnd);
 d4=strtod(pEnd,NULL);
 d5=sqrt((d3-d1)*(d3-d1)+(d4-d2)*(d4-d2));

 printf("The salesman has traveled a total of %.3llf kilometers.\n",d5);
 d1=d3;d2=d4;
}

}
return 0;
}
frowning frowning frowning

  • created

    Jan '12
  • last reply

    Jan '12
  • 1

    reply

  • 115

    views

  • 2

    users

Please use code tags when posting code. Please use the proper problem code, this is FAKETSP.

What result is the judge returning?

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 16 8d

Want to read more? Browse other topics in C and C++ or view latest topics.