Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,626 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,053 people online right now. Registration is fast and FREE... Join Now!




Conversion gallon to litre

 
Reply to this topicStart new topic

Conversion gallon to litre, need help - newbie

jenniweni
post 6 Apr, 2006 - 12:56 AM
Post #1


New D.I.C Head

*
Joined: 6 Apr, 2006
Posts: 10


My Contributions


Hello
I was hoping someone may be able to help me. Ive only just begun learning c++ and I need to convert gallon to litre.

Ive given it a go but it doesnt work.
Can any one shed light on it for me how to do it please???
User is offlineProfile CardPM

Go to the top of the page

sontek
post 6 Apr, 2006 - 12:59 AM
Post #2


D.I.C Regular

Group Icon
Joined: 13 Sep, 2001
Posts: 283



Thanked 1 times

Dream Kudos: 85
My Contributions


What doesn't work about your application? Post your code and i'll be glad to review it smile.gif
User is offlineProfile CardPM

Go to the top of the page

jenniweni
post 6 Apr, 2006 - 01:04 AM
Post #3


New D.I.C Head

*
Joined: 6 Apr, 2006
Posts: 10


My Contributions


Hi Sontek
Ive sent it to your email. Hope thats alright??
User is offlineProfile CardPM

Go to the top of the page

Dark_Nexus
post 6 Apr, 2006 - 01:08 AM
Post #4


or something bad...real bad.

Group Icon
Joined: 2 May, 2004
Posts: 1,309



Thanked 2 times

Dream Kudos: 625
My Contributions


for future reference to the same problem, could you please post your code on the board?
User is offlineProfile CardPM

Go to the top of the page

jenniweni
post 6 Apr, 2006 - 01:25 AM
Post #5


New D.I.C Head

*
Joined: 6 Apr, 2006
Posts: 10


My Contributions


Sure. Sorry. Im new as I said. Anyway Iknow this code probably looks pretty awful but anyway here it is.

CODE

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
   const int MAXGALLON = 20;
   const int STARTVAL = 10;
   const int STEPSIZE = 1;
   int litre, gallon;
   double count, total;
       
   cout << "LITRE  GALLON\n"
        << "-----  ------\n";
       
        gallon = STARTVAL;
        cout << setiosflags(ios::showpoint) << setiosflags(ios::fixed)
             << setprecision(2);
             
        while (gallon <= MAXGALLON)
        {
              gallon = 1 * 3.785;
              cout << setw(4) << gallon
                   << setw(13) << litre << endl;
              gallon = litre + STEPSIZE
        }
         
   system ("pause");
   return 0;
}


This post has been edited by Dark_Nexus: 9 Apr, 2006 - 09:38 PM
User is offlineProfile CardPM

Go to the top of the page

sontek
post 6 Apr, 2006 - 02:04 AM
Post #6


D.I.C Regular

Group Icon
Joined: 13 Sep, 2001
Posts: 283



Thanked 1 times

Dream Kudos: 85
My Contributions


I fixed a few things in your code, I'm not sure if you were using the loop for the assignment but it wasn't need for a conversion..

Things you were doing wrong:

1. You were changing the gallon value rather than the litre.
2. You were missing a semicolon.
3. You were showing the gallons under the litre

heres the new code:
CODE

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
   const int MAXGALLON = 20;
   const int STARTVAL = 10;
   const int STEPSIZE = 1;
   int litre, gallon;
   double count, total;
   
   cout << "LITRE GALLON\n" << "----- ------\n";
   gallon = STARTVAL;
   cout << setiosflags(ios::showpoint) << setiosflags(ios::fixed) << setprecision(2);
   
   litre = gallon * 3.785;
   cout << setw(4) << litre    << setw(6) << gallon << endl;

   system ("pause");
   return 0;
}



Good Luck!
User is offlineProfile CardPM

Go to the top of the page

jenniweni
post 6 Apr, 2006 - 02:24 AM
Post #7


New D.I.C Head

*
Joined: 6 Apr, 2006
Posts: 10


My Contributions


Thank you Xenon. Its good to see where Ive gone wrong.
User is offlineProfile CardPM

Go to the top of the page

sontek
post 6 Apr, 2006 - 02:47 AM
Post #8


D.I.C Regular

Group Icon
Joined: 13 Sep, 2001
Posts: 283



Thanked 1 times

Dream Kudos: 85
My Contributions


*ahem* mad.gif
User is offlineProfile CardPM

Go to the top of the page

jenniweni
post 6 Apr, 2006 - 02:49 AM
Post #9


New D.I.C Head

*
Joined: 6 Apr, 2006
Posts: 10


My Contributions


Sorry Sontek. Can you tell Im tired. Please forgive me.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 03:35AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month