c++

I need some help with some code. Here is the text:
Plot the progress of the rider on the road. With the symbol * draw the number of percents by which a rider has finished the track, then write "." character for unfinished part of the track. Write the percentage of distance traveled.

Then draw a rectangle progress in multi-line (line graph) for 5 riders on the same route.Enter a value of N, which is the same for all rectangles. Use the local variables, pass them into functions.

So if someone can help me to solve this problem ..
Here is my code[doesn't work] :

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 int PercentageOfRoadPassed(double rp,double rl){ return ((rl-rp)/rl) * 100; } void drawPath(float x,int lines) { for (int i = 0; i < lines - (int)x; i++) { if (i == lines/2) { cout << " *"; } else { cout << "*"; } } for (int i = (int)x; i > 0; i--) { if (i == lines/2) { cout << " ."; } else { cout << "."; } } cout << endl; } int main() { int N, lines; float velocity[5]; float time_spent[5]; float route_length[5]; float remaining_path[5]; for (int i = 0; i < 5; i++) { cout << "Enter velocity for competitor " << i + 1 << ": "; cin >> velocity[i]; cout << "Enter the time spent for competitor " << i + 1 << ": "; cin >> time_spent[i]; cout << "Enter the route length for competitor " << i + 1 << ": "; cin >> route_length[i]; remaining_path[i] = route_length[i] - time_spent[i] * velocity[i]; if (remaining_path[i] == 0) { cout << "Competitor " << i + 1 << " has passed" << endl; } else { cout << "Competitor " << i + 1 << " hasn't passed the route yet" << endl; } } cout <<"Enter number of rows to the side of rectangle"<> N; cout <<"Enter number of lines for the graph"<> lines; for (int i = 0; i < 5; i++) { cout << "Competitor " << i + 1 << " (" << PercentageOfRoadPassed(remaining_path[i] , route_length[i]) << "%)" << endl; for (int j = 0; j < N; j++) { drawPath(remaining_path[i],lines); } } return 0; }

Last edited on
Put your code in code tags like this:

 [code] //Your Code Here [/code]

It hurts my eyes, it burns!
Last edited on
Oh sorry, and thanks i didn't noticed
You've gotten your percentages.

I assume that the "drawPath" function doesn't have to draw it that complicatedly. You can make the whole thing out of 10 and check the percentage. Round the percentage. Up to the percentage have * and afterwards put ".". For the place where the rider stopped, put the percentage.

For example, if they went 56% of the way, you'll round to 60 (just for the drawing part). The first 5 characters will be "*" followed by "56%" and then 4 "."

^If your professor or whatever didn't specify how to do it, this is a pleasant and easy to way to do it.

As for the line graph, I'm not sure how they expect it. You can't really draw lines from point to point on the console. A bar graph would be easier to replicate. However, I'm not too sure by your description what the graph should even be graphing.
Topic archived. No new replies allowed.