Homework help?

Hello. I am having trouble with my homework. If anyone could help me and and walk me through it that would be great.

The assignment was to:

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
Write a program that computes how many meters an object falls in 1 second, 2 seconds, 
etc., up to 10 seconds.
First create a Raptor flowchart. For this assignment you will need to switch to 
intermediate mode.
Your Raptor program should:
1. Have a procedure called FallingDistance which has one input parameter, seconds, 
and one output parameter, distance.
2. Compute the distance an object falls using this formula: 
d = 0.5 * 9.8 * t^2 (t being seconds)
3. The main program should call FallingDistance within a loop which passes the 
values 1 through 10 as arguments.
4. Print a table with seconds and falling distance in meters.
Once your Raptor flowchart executes correctly, upload your .rap file. Make sure your 
name is on the flowchart in a comment. 
Sample Output (This program has no input)
Seconds   Distance
==============
1              4.9
2              19.6
3              44.1
4              78.4
5              122.5
6              176.4
7              240.1
8              313.6
9              396.9
10              490


I have created the flowchart and now I need to write it in C++ using visual basic. This is what I have so far. (Yes I know its wrong.. probably by alot.. I have tried as you can see)

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
#include <iostream>
#include <iomanip> 
using namespace std;


double FallingDistance(double, double);



int main()
{
	double Seconds = 1;
	cout << "Seconds                Distance\n";
	cout << "===============================\n";
	
	for (double Seconds = 1; Seconds <= 10; Seconds = Seconds + 1)

	{
	
	double FallingDistance(double Seconds, double distance);

	cout << fixed << showpoint << setprecision(2);
	cout << Seconds << "     " << FallingDistance << endl;
	}
	



}

double FallingDistance (double Seconds, double distance)

{
	
	double Distance = .5 * 9.8 * Seconds * Seconds;
	return Distance;
	

}
	


Can you please help me get the right output the example displays?
Last edited on
3. The main program should call FallingDistance within a loop which passes the
values 1 through 10 as arguments
.


Your function is passing seconds and distance. It doesn't need to. It just needs to pass the time, as everything else in the calculation is a constant. Just pass in the time as a parameter and return the equation given in point two of your specification above. You've got yourself a quick, one-line function there.

Then you'd just call it in a loop, passing in the new time at each iteration.
Last edited on
See you are not calling function correctly, it should be a syntax error.
on line 22 it should be like this.

FallingDistance( Seconds);

the reason for only one argument is that you have used this in main and there is no other thing in the main to be sent to the function. Further you will also need to change this in the definition and prototype.

3rd thing which you are doing wrong is you are not storing the result of the return by the function in anything and you need to store it in some variable and then print that variable.

4th thing there is no need for second to be double.
see this program if have completed this.


#include <iostream>
#include <iomanip>
using namespace std;


double FallingDistance(double);



int main()
{
double Seconds = 1;
double fallingDistance=0;
cout << "Seconds Distance\n";
cout << "===============================\n";

for (double Seconds = 1; Seconds <= 10; Seconds = Seconds + 1)

{

fallingDistance=FallingDistance(Seconds);

cout << fixed << showpoint << setprecision(2);
cout << Seconds << " " << fallingDistance << endl;
}




}

double FallingDistance (double Seconds)

{

double Distance = .5 * 9.8 * Seconds * Seconds;
return Distance;


}
To add, you declare the variable Seconds in two places, once in main and another time in the for loop. Pick one place or the other.

You don't technically need to store fallingDistance as a variable:
cout << Seconds << " " << FallingDistance(Seconds) << endl;
Works just fine.

The FallingDistance function can simply be:
1
2
3
4
double FallingDistance(double Seconds)
{
  return .5 * 9.8 * Seconds * Seconds;
}


Last edited on
Topic archived. No new replies allowed.