Member Avatar for exonwarrior

Hey all,
I'm writing a program in C++ for a contest. The code executes no problem on my computer at school that I'm writing it on. I get all the correct answers. When I upload it however, it keeps on saying "runtime error (SIGSEGV)"
Please Help!!
here's the link to the site so you know what the program is supposed to do.
https://hs.spoj.pl/problems/HS09UBT/
Thanks in Advance,
Dave

Recommended Answers

All 7 Replies

How can we possibly tell you what's wrong with the code without seeing it?

Member Avatar for exonwarrior
#include<iostream>
#include<math.h>

using namespace std;

main(){

           int *array;
           array = new int[1000];

           int T = -1;
           double v;
           int f1;
           int f2;

            for(int i = 0; T!=0; i++){
                cin >> T >> v >> f1 >> f2;
                int distance = (T*1450)/2;
                array[i] = distance;
            }
            for (int k = 0; array[k]!=0; k++){
                cout << array[k] << "\n";
            }
       system("PAUSE");               
       return 0;
       }

> for (int k = 0; array[k]!=0; k++)
Use the value of i from the previous loop, to count how many elements you have.

You're assuming your array is filled with zeros - it isn't.

Member Avatar for exonwarrior

> for (int k = 0; array[k]!=0; k++)
Use the value of i from the previous loop, to count how many elements you have.

You're assuming your array is filled with zeros - it isn't.

so

for (int k = 0; k<i; k++){

should work?
Cause it ain't :P

Do you type in more than 1000 numbers?

Show how you run the code, and the output you get.

Paste a terminal log of say 10 lines of input (does it crash at that point?)

Member Avatar for exonwarrior

Do you type in more than 1000 numbers?

Show how you run the code, and the output you get.

Paste a terminal log of say 10 lines of input (does it crash at that point?)

It's for a contest. They only give you two examples of input and output (so you can check if your program works). The 1000 is because I don't know how many test cases they'll do. It works flawlessly on my machine though

Well I'm guessing they pass more than 1000 (perhaps).

In any event, you should check that you don't go over your array limits.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.