I feel so dumb, please help.

I've recently started a university night course in c programming, i'm trying my best to learn as much as I can and it's a "beginners course" but everyone else there is already educated to university standard and are all mostly doing computing courses in university too, I however am only educated to high school level. That being said I feel like i'm falling slightly behind or not picking up as quick as everyone else is. I'm stuck on an assignment question we have due in for next week and it's starting to baffle me.

Here's my assignment question : Exercise 1.

When a car is travelling along a road at a speed of V miles per hour, the stopping distance, S feet, is given by:- S = ( V * V ) / 20 + V Write a C program to produce a table showing stopping distances for speeds in the range 10 to 40 miles per hour in steps of 10 miles per hour. The output from the program should be as follows:-
Speed distance
10 15
20 40
30 75
40 120



Below is the code I have so far, I feel like for the most part i've done it right but i'm missing something and it's coming out completely different than what it should be, without actually answering the question for me can anyone help me with what I need to do by telling me what i've done wrong?

Thanks in advance for any replies I may get!

1
2
3
4
5
6
7
8
9
10
11
12
  
#include<stdio.h>
void main ()
{  
int MPH  = 10;
int distance;
temp_loop:
distance = (MPH * MPH) / 20 + MPH;
printf ("%2d MPH \n = %2d distance");
MPH ++;
if (MPH <= 40 ) goto temp_loop;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
//learn to indent
#include <stdio.h>
int main() { //main must return int
	int MPH = 10;
	int distance;
temp_loop:
	distance = (MPH * MPH) / 20 + MPH;
	//printf("%2d MPH \n = %2d distance"); //compilers don't read minds, you must tell what variable to print
	printf("%2d MPH \n = %2d distance", MPH, distance); //your line break is on the wrong position
	MPH++; //this will increase MPH from 10 to 11, your example jumps to 20, ¿which one do you want?
	if(MPH <= 40)
		goto temp_loop; //read about loops
}

Topic archived. No new replies allowed.