Project: read file and find maximum slope

Ok so I've been learning C++ for about a month now and am new to the language and anyway I told my dad I'd help him with something he's working on since I'm taking a class in C next semester anyway involving slope and reading files.
So basically theres a list of numbers from results for a test with the x value as time and y as power. So what the program has to do is read in the x and y values sequencially and calculate he slope with each one. It then has to pick the highest slope as the result and display that as the output.

If someone could tell me how to do this it would be really helpful.
-Blake
Last edited on
Can you do it yourself on a piece of paper with 5 or 6 lines of data?

Remember, slope = y / x.
Also, use doubles for all your numbers.

Some pseudocode:
double max_slope = 0.0
double x, last_x
double y, last_y
get data from file into last_x. last_y
while (get data from file into x, y):
  double m = (y - last_y) / (x - last_x);
  if (m > max_slope):
     max_slope = m

Hope this helps.
Topic archived. No new replies allowed.