1. ## I need help please...

I have trouble doing this.
I try making it but it wont work.
This is in while loop.

1. Write a C program that converts gallons to liters. The program should display gallons from 10 to 20 in 1-gallon increments and the corresponding liter equivalents. Use the relationship that 1 gallon contains 3.785 liters.

2. Write a C program that converts feet to meters. The program should display feet from 3 to 30 in 1-foot increments and the corresponding meter equivalents. Use the relationship that 1 meter equivalent to 3.728 feet.

2. WHAT HAVE YOU TRIED?!

hopefully that stands out. here is an example of counting from -42 to 42:

Code:
```int start = -42;
int end = 42;

while ( start <= end )
{
cout << start << endl;
start++;
}```
this is basically giving you the answer, apart from the logic you must add to suit your requirements. i.e., what number do you have to start at? end at? inside the loop you print something (cout)? inside the loop you do some calculation (start++)?

WHAT HAVE YOU TRIED?!

hopefully that stands out. here is an example of counting from -42 to 42:

Code:
```int start = -42;
int end = 42;

while ( start <= end )
{
cout << start << endl;
start--;
}```
this is basically giving you the answer, apart from the logic you must add to suit your requirements.
but how do i do it in converting the questions...its confusing..

4. 1. Write a C program that converts gallons to liters. The program should display gallons from 10 to 20 in 1-gallon increments and the corresponding liter equivalents. Use the relationship that 1 gallon contains 3.785 liters.
ok so i gave you an example. your program must start at 10, and end at 20 (inclusive). directly from your pasted assignment, it says that 1g = 3.785l. therefore 10g = 10*3.785l, 15g = 15*3.785g, etc. inside your loop you need to convert your number of gallons (starting at 10) to litres and print it.

give that a shot or post actual work/attemps or ask what you dont understand more specifically.

ok so i gave you an example. your program must start at 10, and end at 20 (inclusive). directly from your pasted assignment, it says that 1g = 3.785l. therefore 10g = 10*3.785l, 15g = 15*3.785g, etc. inside your loop you need to convert your number of gallons (starting at 10) to litres and print it.

give that a shot or post actual work/attemps or ask what you dont understand more specifically.
is this right?

int start = 10;
int end = 20;
liters = (3.785);

printf("Input gallons from 10 to 20:\n");

while ( start <= end )
{
10; start = 10 * 3.785;
start++;

and the problem now too is converting int to double

6. Code:
```    int start = 10;
int end = 20;
const double litersPerGallon = 3.785;  //edit: not constant, const
double liters = 0.0;

printf("gallons to liters, from 10 to 20:\n");

while ( start <= end )
{
liters = start * litersPerGallon;
printf("\n %d gallons is %4.3lf liters", start, liters);
start++;
}```
This is a bit of a gift, but take it and use a similar logic, to do the second part of your assignment.

You need to "marinate" in this kind of logic, because it's quite basic, and used all the time. Let it soak in, very well.

Code:
```    int start = 10;
int end = 20;
constant double litersPerGallon = 3.785;
double liters = 0.0;

printf("gallons to liters, from 10 to 20:\n");

while ( start <= end )
{
liters = start * litersPerGallon;
printf("\n %d gallons is %4.3lf liters", start, liters);
start++;
}```
This is a bit of a gift, but take it and use a similar logic, to do the second part of your assignment.

You need to "marinate" in this kind of logic, because it's quite basic, and used all the time. Let it soak in, very well.
is the constant included?
ok thank you very much~ thank so much~
can i ask? what is 4.31f for? how did you get it?

8. Originally Posted by rickajoie
is the constant included?
ok thank you very much~ thank so much~
can i ask? what is 4.31f for? how did you get it?
The constant data type modifier, just tells your compiler "this variable should never be changed by the program". It's optional, but good to use, although I frequently forget to use it, myself.

%4 in printf(), tells printf() that this variable number should be printed in a field that is 4 digits wide. The .3 tells printf() that this variable should have 3 digits printed, after the decimal point.

"lf" tells printf() that the data type here, is a double (think of it as a long float).

The joy and the curse of C (and programming in general), is that you have to keep practicing with it, or you'll forget it. If you only have a year or so of programming in C, and you step away from it for 3 years, you'll be *amazed* at all the things that you've forgotten.

You're welcome.

The constant data type modifier, just tells your compiler "this variable should never be changed by the program". It's optional, but good to use, although I frequently forget to use it, myself.

%4 in printf(), tells printf() that this variable number should be printed in a field that is 4 digits wide. The .3 tells printf() that this variable should have 3 digits printed, after the decimal point.

"lf" tells printf() that the data type here, is a double (think of it as a long float).

The joy and the curse of C (and programming in general), is that you have to keep practicing with it, or you'll forget it. If you only have a year or so of programming in C, and you step away from it for 3 years, you'll be *amazed* at all the things that you've forgotten.

You're welcome.
ok thank you~ ehehe~ actually im just new in programming im still a freshmen...

10. Originally Posted by rickajoie
ok thank you~ ehehe~ actually im just new in programming im still a freshmen...
You're more than one person? Are you a conjoined twin?

11. I think we need to revise our homework policy and start doing these peoples homework for them, so when they get out in the world they utterly fail right out of the gate and never plague us with their inane code.

12. Originally Posted by rags_to_riches
You're more than one person? Are you a conjoined twin?
conjoined twin?? no im not...>.<

13. Originally Posted by abachler
I think we need to revise our homework policy and start doing these peoples homework for them, so when they get out in the world they utterly fail right out of the gate and never plague us with their inane code.

14. Originally Posted by rickajoie