2

I am facing an error, that is a presentation error. Being a beginner to c++ , I am stuck on the following question:

Two cars (X and Y) leave in the same direction. The car X leaves with a constant speed of 60 km/h and the car Y leaves with a constant speed of 90 km / h.

In one hour (60 minutes) the car Y can get a distance of 30 kilometers from the X car, in other words, it can get away one kilometer for each 2 minutes.

Read the distance (in km) and calculate how long it takes (in minutes) for the car Y to take this distance in relation to the other car.

Input:
30

Output:
60 minutos (minutes in portuguese)

Now, upon submitting the code it says presentation error. Could someone help me find a solution to this error. Thank you in advance.

My code:

#include <iostream>

using namespace std;

int main(){
  int Y;

  cin >> Y;
  cout << 2*Y << " minutos " << endl;

  return 2*Y;
}
Community
  • 1
  • 1
Henry Worxlor
  • 23
  • 1
  • 5
  • 1
    This program compiles and runs without any issues. There's nothing wrong with this code. – Sam Varshavchik Apr 20 '16 at 02:56
  • 1
    Is this a competition problem? "presentation error" means your answer does not match to the expected format. – Minhas Kamal Apr 20 '16 at 02:57
  • and change "minutos" to "minut**e**s" – Minhas Kamal Apr 20 '16 at 02:58
  • 1
    It produced a runtime error on ideone: http://ideone.com/LQTzxY. I believe this is due to the non-zero return (http://stackoverflow.com/questions/8696698/in-the-main-function-of-a-c-program-what-does-return-0-do-and-mean answer by Brent Worden). Changing it to return 0; makes it run without any runtime errors. –  Apr 20 '16 at 03:06
  • 1
    @abhishek_naik Really good comment I believe that his presentation error is caused by the fact that he return number different than zero. Simply he should print the output in cout. I hope I understood him well. – FieryCod Apr 20 '16 at 03:25

2 Answers2

1

To fix your problem try to return zero as the main function should return it, if your code is clear from errors.

Try to follow that convention to always return 0 in main.

Your code should look like this:

#include <iostream> 
using namespace std;

int main()
{ 
    int Y; 
    cin >> Y; 
    cout << 2*Y << " minutos " << endl;         

    return 0; 
}

To conclude simply use cout instead of return.

FieryCod
  • 1,674
  • 1
  • 19
  • 27
  • 1
    Are you sure this is the 'presentation error' that he is talking about? He has not mentioned anything about 'runtime error' which is caused by non-zero return (please refer my comment). –  Apr 20 '16 at 03:16
  • 1
    " the higher number it is, the more serious error you have". Is that so? Can you link to a source verifying the same? – CinCout Apr 20 '16 at 04:15
  • @CinCout Sory you got right I checked one more time and It is my mistake . Thanks for your comment. – FieryCod Apr 20 '16 at 05:08
1

PE is a common error in OJ of ACM. you can check space , newline charactor or something you missed. for example:

#include <iostream>

using namespace std;

int main(){
  int Y;

  cin >> Y;
  cout << 2*Y << " minutos (minutes in portuguese)" << endl;

  return 0;
}

you can have a try, good luck for you.

JellyWang
  • 51
  • 1