IF you run this code you will understand what I am trying to say.
The two columns that are displayed when you run this code is distance and time. The time column needs to be reversed. Ascending rather than descending. I've attempted to modify the for statement with plethra of options and nothing seems to work.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
usingnamespace 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 = 12000; distance >= 500; 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;
}
Salem c, if I do what you suggested it changes both columns to opposite order(flips values).
Niccolo, I'm very green with C++, I've attempted to alter the for statement to different values trying to make it do what I want. No, it's not that I think it takes less time. It just makes more sense to have 12000 meters be equal to 10 seconds. IF one falls they won't be falling 12000 meters for 49 seconds... 11500 meters for 48 seconds... The logic of that doesn't make sense. Shouldn't it be 12000 meters 10 secs etc etc?
I don't quite understand what I am doing within my code. I've had a lot of help in getting it written. With that said, the 500 should be next to 49 seconds 12000 meters should be next to 10 seconds.
I hope that helps on understanding what I am asking for.
You're misunderstanding the problem. One is on top of Everest, you fall, the fall is about 12000 meters. It makes sense that when one has 500 meters left of falling that also one has been falling for 49 seconds.
Ok, that makes a little more sense, it isn't the time from a particular height, it is the time at each sample toward the ground...ok, so....the reversal I proposed does that.
Now, as to how...well, it's a basic algebra problem.
You want the value of 12000 to equal the value from 500, 11500 to equal that of 1000
Consider, first, what happens with a simple reversal
12000 - distance...
Now, the chart would start at 12000, but the "distance left" is actually 0
Then, 11500 would become...500
11000 would be, 1000....
You see from this it is a tad oversimplified, but the parameter supplied to distance has now been
reversed....the first objective you stated....a reversal.
It changes "distance to go" to "distance we've gone...."
That is, at 12000 we've moved 0, at 11500 we've moved 500, etc....
However, in fact, this isn't an exact reversal of your chart. The chart clearly required that 12000 equate to the value given at 500....this offsets the chart by 500....so....12500 becomes the "initial" value for the reversal, thus 12500 - distance...
Not that I still fully agree here, but....
If Everest were 12500 meters tall, maybe....
Put another way, if Everest is 12000 meters, and the jump begins there, than AT 12000 meters the time traveled to that point (which would be the start) is 0.
Anyway....that's the idea with this reversal itself
There is clearly "total distance" (tot) from the peak to sea level.
There is the "distance that has been already travelled" (tra).
There is "remaining distance" (rem).
tot == tra + rem
rem == tot - tra
There is "time used to travel so far". Time to fall 'tra' meters.
Before the jump tra == 0. Before the jump rem == tot. Before the jump the time is 0.
There will be splash when tra == tot. There will be splash when rem == 0.
It is up to you what you do show:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <iomanip>
#include <cmath>
int main()
{
using std::setw;
std::cout << std::fixed;
std::cout.precision(2);
constexprint tot {12000};
for ( int tra = 0; tra <= tot; tra += 1000 )
{
int rem = tot - tra;
std::cout << setw(6) << tra
<< setw(6) << rem
<< setw(8) << sqrt(tra) << '\n';
}
}
IF you run this code you will understand what I am trying to say
Nope.
Perhaps it would be best if you worked out the first few INTENDED outputs by hand (well, calculator anyway) and set them out in columns for us - then we might be able to infer what you want.
1 2 3 4
int beforeSplat(int distance)
{
return (sqrt((2*distance)/9.8));
}
Well, make those int into double ... that's a C++ problem.
The more significant mathematics problem is that this formula (from rearranging one of the suvat eqns) gives you ... the time taken to travel distance FROM REST at acceleration g=9.8 m s-2. In other words, such a function would be better named timeFromStart, not beforeSplat.
If you want remaining time (who knows, you are far from clear) then maybe you want some combination of:
sqrt(2.0*heightOfEverest/g) is the total time to fall (g=9.81 in metre-second units)
sqrt(2.0*(heightOfEverest-currentHeight)/g) is the time from start to the current position
If you want the remaining time (again, who knows) then just subtract them.
PS. It really doesn't help if you start two threads on exactly the same problem.
PPS. Why don't you state the original question, not your interpretation of it.