Reversing numbers on a table

I have this code completed, but whenever I run it, the time is backwards. I need it to output 49-10 not 10-49

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;

//***************************
// Function beforeSplat     *
// This function calculates *
// the time taken to fall.  *
//***************************

int beforeSplat(int distance)
{
    return (sqrt((2*distance)/9.8));
}

//*****************************
// Function printHeader       *
// This function displays     *
// the table for information. *
//*****************************

void printHeader(ofstream& Splat)
{
    Splat<<"  Distance \t     Time\n"
         <<"  (meters)\t  (seconds)\n"
         <<"~~~~~~~~~~~~~~~~~~~~~~~"
         <<endl;
}

//*****************************
// Function print             *
// This function displays     *
// the output of information. *
//*****************************

void print(int distance, int time, ofstream& Splat)
{
    Splat<<"|  "<<left<<setw(13)<<distance
         <<" "<<time<<"   |"
         <<endl;
}

//*****************************
// Function main              *
//*****************************

int main()
{
    ofstream Splat;
    Splat.open("Everest.out");
    int time;
    printHeader(Splat);

    for(int distance = 500; distance <= 12000; distance+=500)
    {
        time=beforeSplat(distance);
        print(distance, time, Splat);
    }

        Splat<<"~~~~~~~~~~~~~~~~~~~~~~~"
             <<"\n\n\n\t Everest.out has been saved to file.";
    Splat.close();
    return 0;
}
for(int distance = 12000; distance >= 500; distance-=500)


CodeNovice01 wrote:
time is backwards
In your dreams.
Last edited on
No sorry your advice didn't help it didn't change any sort of formatting.

If you run my code you will see two columns the one on the right (time) needs to be reverse order. It's backwards! and needs to be ascending rather than desending
This is a duplicate post....and, what @lastchance is saying is that the shorter the distance, the less the time...but

time = beforeSplat( 12500 - distance );

..reverses the output
Topic archived. No new replies allowed.