# Thread: Homework Help, simple program, unsure newbie :(

1. ## Homework Help, simple program, unsure newbie :(

Hi everyone. I read all the "before you post, know this" stuff, so I hope I get it right!

First, this is a homework that I have been stuck on for a month. I have a serious mental block when it comes to programming for some reason I did numerous Goggle searches but found nothing. I found a similar program on here, but I didn't want to copy theirs, for obvious reason. I would really like to learn how to program in C. Plus, the one that is posted was really buggy.

The instructions are as followed;
"HW2 computes a list of conversions from miles per hour to feet per second. The list should be from 0 to 80 mph with an increment the user inputs. After the prompt 'input increment:' is given, your program should display the answer on the screen. Output should be %5.0f %5.1f."

Second, I wrote a program is a fine program in itself, it converts mph to fps very nicely. BUT it is incorrect because it does not do it in "user inputted increments." I didn't do what was asked, and I have been avoiding this program ever since.

This is where I am stuck! I don't even know where to start with the increments.

I know I need to have the user input an increment from 0 to 80, then the program should print out a list of conversions in the specific increment.

Should I use "increment" as declared variable? Then use it in some sort of equation that the program executes when the user assigns "increment" a value?

I just need a push in the right direction I think.

I will include the original program, forgive me if the code tags suck, I am very new at all of this.
Code:
```#include <stdio.h>
#define SCALE_FACTOR (1.46666667f)

int main(void)
{

float mph, fps;

printf("Enter mph: ");
scanf("%f", &mph);

fps = mph * SCALE_FACTOR;

printf("Feet per second equivalent: %5.1f\n", fps);

return 0;
}```
Any input from the experts would be greatly appreciated! (I would go to my professors office hours, but it is a holiday and he is currently out of town)

2. Originally Posted by Aslan14
I know I need to have the user input an increment from 0 to 80, then the program should print out a list of conversions in the specific increment.
Actually, no. The user might input an increment such as 5, then your program will loop 0, 5, 10, ..., 75, 80, converting each of these values.

3. You're in BIG trouble now, Aslan14! (needed to clean my glasses! )

You can't just come in here, read and follow the homework policy, show real effort in your description of the problem, AND use code tags!

This is unheard of!!

Welcome to the Forum, Aslan14!

So first, add a message telling the user to input an interval, and get that.

Then use a for loop to give your output, and include the interval, and a % operator:

Say interval is 10:
Code:
```int interval=10;
for(i=0;i<80(whatever is right); i++) {
if(i % interval==0)
}```
if you don't want the data to be printed on the first loop through (when i is zero, then add the part in green):
Code:
`if(i % interval==0 && i)`

Say interval is 10:
Code:
```int interval=10;
for(i=0;i<80(whatever is right); i++) {
if(i % interval==0)
}```
I think something like the following would be much better (clearer and more efficient):
Code:
```for (i = 0; i < 80(whatever is right); i += interval) {
}```

5. I'm "selling" the mod operator, today. No idea why!

Aslan, listen to anduril, OK?

You're in BIG trouble now, Asian14!
Daymn Adak... you like to scare the bejeebers outa me....

7. I'm getting punchy from messing around with sorting algoriithms, too much.

Found a good one though!

8. It's Aslan not Asian LOL. Let me close the racist door there for you before the draft gets in.

9. Aslan probably left it open...he's on the move.

10. I told you I was getting punchy -

apologies, Aslan!!

11. Hello again everyone! I just wan to say I got a good chuckle from your replies!

Sorry for the absence, my computer took a nose dive (damn HPs)! This is what I have, but I apparently am not doing the "for" loop right.

Code:
```#include <stdio.h>
#define SCALE_FACTOR (1.46666667f)

int main(void)
{
int i = 0;
float fps, increment;

printf("Enter increment between 0 and 80: ");
scanf("%f", &i);

{
for (i = 0; i <== 80; i+= increment )
}

{
fps = i * SCALE_FACTOR;
printf("Feet per second equivalent: %5.2f\n", fps);
}
return 0;
}```

I first tried using mph instead of i, so it looked like;
Code:
` int mph = 0`
But that didn't seem to be working, so I went with 'i".

The errors I am getting are;
hw02.c: In function `main':
hw02.c:17: error: syntax error before '=' token
hw02.c:17: error: syntax error before ')' token

Any suggestions?

12. <== should be <=

13. Originally Posted by Aslan14
Hello again everyone! I just wan to say I got a good chuckle from your replies!

Sorry for the absence, my computer took a nose dive (damn HPs)! This is what I have, but I apparently am not doing the "for" loop right.

Code:
```#include <stdio.h>
#define SCALE_FACTOR (1.46666667f)

int main(void)
{
int i = 0;
float fps, increment;

printf("Enter increment between 0 and 80: ");
scanf("%f", &i);

{
for (i = 0; i <== 80; i+= increment )
}

{
fps = i * SCALE_FACTOR;
printf("Feet per second equivalent: %5.2f\n", fps);
}
return 0;
}```

I first tried using mph instead of i, so it looked like;
Code:
` int mph = 0`
But that didn't seem to be working, so I went with 'i".

The errors I am getting are;
hw02.c: In function `main':
hw02.c:17: error: syntax error before '=' token
hw02.c:17: error: syntax error before ')' token

Any suggestions?
You are correct... your for loop is not going to work as the syntax errors have indicated.
First <== is not a valid token in C.
Second your bracketing is all wrong.

14. ## Yay!!

After fixing the brackets and the relational operator (how did I miss those?), I was getting a really really weird output!
Code:
` "Feet per second equivalent: -3149642752.00"`
I remember seeing somewhere in my book that this is bad... LOL
So, had to do a little internet research because I figured out I was missing an expression to add the increment to the mph!

Thanks for everyone's help! (you may hear more from me, I am really no good at programming!)