help with experiment using c++

Hi, I need to get this code to ask for the initial speed, omega. I understand it would need a prinf statement followed by scanf, but do not know what to include in them or what else to do. Also how do I get it to calculate values for the angle theta (in radians) Thank you in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
    main()

    {

   int i;                // step counter
      float theta = 0;   // initial value for angle
      float omega = 0.2; // initial value for angular speed
      float time = 0;    // initial time
      float dt = 0.01;   // time step
      int steps = 100;   // number of steps

   for(i=0 ; i<steps ; i++) {
          time = time + dt;
          printf("Step number %i Time equals %f\n",i,time);
      }
      system("PAUSE");
   }
Last edited on
aren't you seeing your previous post?
look at there
Can't help with your calculation, but if you're really stuck provide the formula you wish to use.

Use double instead of float, it's 2016.

Here's how you'd use scanf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>

int main()
{
	int i;                // step counter
	float theta = 0.0;   // initial value for angle
	float omega = 0.0; // initial value for angular speed
	float time = 0.0;    // initial time
	float dt = 0.01;   // time step
	int steps = 100;   // number of steps

	printf("Please enter initial speed (omega) ");
	scanf("%f", &omega);
	for(i = 0 ; i < steps; i++) 
	{
		time += dt;
		printf("Step number %i Time equals %f\n", i, time);
	}
	
	system("PAUSE");
}
BTW: your title is misleading, which is why you're not getting answers. You're not "experimenting with C++" you're writing in C.
Also I forgot to point out that main() returns an int
Topic archived. No new replies allowed.