0

I was solving this problem on SPOJ.

http://www.spoj.com/problems/NECSTASY/

Problem Image

And this my code.

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>

const float PI=3.14159265;

using namespace std;

int main()
{
    float d,x,y,t;
    while((cin >> d >> x >> y >>t)!=EOF)
    {
        float u= PI*(t/180);
        float l = (d-y);
        float k = l*(1/sin(u/2));
        float h = k+x;
        cout << fixed << setprecision(2) << h << endl;
    }
    return 0;
}

I am facing a problem with the fact that no of test cases is not given.

How do I deal with that??

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
dreamboat
  • 159
  • 1
  • 3
  • 16

2 Answers2

1

You can use the code for test.

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <stdio.h>
const float PI=3.14159265;
using namespace std;
int main()
{
float d,x,y,t;
while(getchar()!=EOF)
{
 cin >> d >> x >> y >>t;
 float u= PI*(t/180);
 float l = (d-y);
 float k = l*(1/sin(u/2));
 float h = k+x;
 cout << fixed << setprecision(2) << h << endl;
}
return 0;
}
1

Just replace while((cin >> d >> x >> y >>t)!=EOF) with while(cin >> d >> x >> y >>t).

cin will evaluate to false when it fails to read.

For more details please read: std::basic_ios::operator bool

Returns true if the stream has no errors and is ready for I/O operations. Specifically, returns !fail().

EOF on the other hand is an integer constant expression of type int and negative value (macro constant) and would not come equal to false.

Gyapti Jain
  • 4,056
  • 20
  • 40