![]() |
| | #1 |
| *depressed* Join Date: Sep 2009 Location: Philippines
Posts: 14
| 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. please help me...im still a newbie...and still new to this... Last edited by rickajoie; 09-09-2009 at 12:05 AM. |
| rickajoie is offline |
| | #2 |
| Registered User Join Date: Oct 2006 Location: Canada
Posts: 848
| 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++;
}
|
| nadroj is offline |
| | #3 | |
| *depressed* Join Date: Sep 2009 Location: Philippines
Posts: 14
| Quote:
| |
| rickajoie is offline |
| | #4 | |
| Registered User Join Date: Oct 2006 Location: Canada
Posts: 848
| Quote:
give that a shot or post actual work/attemps or ask what you dont understand more specifically. | |
| nadroj is offline |
| | #5 | |
| *depressed* Join Date: Sep 2009 Location: Philippines
Posts: 14
| Quote:
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 Last edited by rickajoie; 09-09-2009 at 12:43 AM. | |
| rickajoie is offline |
| | #6 |
| Registered User Join Date: Sep 2006
Posts: 2,512
| 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++;
}
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. Last edited by Adak; 09-09-2009 at 01:07 PM. |
| Adak is offline |
| | #7 | |
| *depressed* Join Date: Sep 2009 Location: Philippines
Posts: 14
| Quote:
ok thank you very much~ thank so much~ can i ask? what is 4.31f for? how did you get it? Last edited by rickajoie; 09-09-2009 at 02:22 AM. | |
| rickajoie is offline |
| | #8 | |
| Registered User Join Date: Sep 2006
Posts: 2,512
| Quote:
%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. | |
| Adak is offline |
| | #9 | |
| *depressed* Join Date: Sep 2009 Location: Philippines
Posts: 14
| Quote:
| |
| rickajoie is offline |
| | #10 |
| and the Hat of Ass Join Date: Dec 2007
Posts: 731
| |
| rags_to_riches is offline |
| | #11 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,929
| 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.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline |
| | #12 |
| *depressed* Join Date: Sep 2009 Location: Philippines
Posts: 14
| |
| rickajoie is offline |
| | #13 |
| *depressed* Join Date: Sep 2009 Location: Philippines
Posts: 14
| |
| rickajoie is offline |
| | #14 |
| Registered User Join Date: Oct 2006
Posts: 263
| not so much mad as annoyed. it's pretty obvious that you did not read the forum rules before posting. you basically came on here and asked us to write your code for you without showing any evidence that you had already tried to do it yourself or search for answers from any of the MANY sources of information on this subject. |
| Elkvis is offline |
| | #15 | |
| *depressed* Join Date: Sep 2009 Location: Philippines
Posts: 14
| Quote:
Last edited by rickajoie; 09-10-2009 at 06:32 AM. | |
| rickajoie is offline |
![]() |
| Tags |
| program, while statement |
| Thread Tools | |
| Display Modes | |
|