Need help with this conversion program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 4
Reputation: kama is an unknown quantity at this point 
Solved Threads: 0
kama kama is offline Offline
Newbie Poster

Need help with this conversion program

 
0
  #1
Nov 30th, 2004
Hello, I need to create a program that will read in a weight in kilograms and grams and will output the equivalent weight in pounds and ounces. I need to use 3 functions: for input, calculation, and output. I also need to have a loop that will let the user repeat this computation for new values, which will let the user whether they want to compute again. As you know there are 2.2046 pounds in a kilogram, 1,000 grams in a kilogram, and 16 ounces in a pound. If anyone is willing to assist me on creating a layout or to help to get me started for this program I will appreciate it. Thanks.

-Kama
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 4
Reputation: kama is an unknown quantity at this point 
Solved Threads: 0
kama kama is offline Offline
Newbie Poster

Re: Need help with this conversion program

 
0
  #2
Nov 30th, 2004
this is what I have so far with the program. I am struggling on how to create these functions, PLease help. As you know the stuff you see with the "//" is just the description of the parts.

  1. //directives
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. //function prototypes
  6. void input(int& kilograms,
  7. int& grams);
  8.  
  9. void calculate;
  10.  
  11. void output;
  12.  
  13. //main function
  14. int main ()
  15.  
  16. {
  17. int kilograms;
  18. int grams;
  19. int pounds;
  20. int ounces
  21.  
  22. //begin main function executables
  23. void input(int& kilograms,
  24. int& grams);
  25.  
  26. void calculate;
  27.  
  28. void output;
Last edited by alc6379; Dec 1st, 2004 at 2:15 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Need help with this conversion program

 
0
  #3
Dec 1st, 2004
Just looking at this, there seems to be very little you've actually done. I don't program that much, if any, and I probably could have framed out what you've got there, no offense.

What part are you stuck on? I wouldn't write any code for you, but wouldn't you first want to start by looking for a formula to convert grams to ounces, or something similar, and integrating that into your calculate function? The functions for input and output should be fairly basic, too-- your textbook should clearly outline how to deal with user input and output, as that's something EVERY program should do.

I mean, if you know 1 kilo is = 1000 grams, 1 lb is 16 oz, and 1 kilo is = 2.20046 lbs, you can figure it all out:

1 kilo = 35.20736 ounces

so

1 gram = 0.03520736 ounces

There you go right there. Just being me, and I'm sure someone will come with a better way if I'm wrong, I'd get the input in kilos and grams. Then, convert the kilos to grams. Convert the total grams to ounces, and then work out how many pounds and ounces are in that amount(use a modulus for that? I dunno...)

Disclaimer: I'm not a programmer, but that's what I'd think to do logically. Take someone else's advice before mine, or use my advice only in the event of a lack of more suitable advice.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Need help with this conversion program

 
0
  #4
Dec 1st, 2004
in fact, he's done nothing at all beyond declaring some variables and function prototypes (which were probably just copied from the assignment paper).

Do your own homework kama, it's the only way you'll ever learn anything.

Questions like yours make me believe there should be a minimum requirement of a college degree to be allowed onto the internet...
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 41
Reputation: varunrathi is an unknown quantity at this point 
Solved Threads: 1
varunrathi's Avatar
varunrathi varunrathi is offline Offline
Light Poster

Re: Need help with this conversion program

 
0
  #5
Dec 1st, 2004
here`s the code to convert weight in kg into pounds

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

struct weight
{
int w1,w2;
};
weight take() //function ti take input
{
weight wt1;
cout<<"Please enter kg part:";
cin>>wt1.w1;
cout<<"\nplease enter the gram part:";
cin>>wt1.w2;
return wt1;
}

weight calculate(weight wt1)
{
weight wt;
int grams = wt1.w1*1000 + wt1.w2;
float totalounces = grams*0.0352736;
int pounds = totalounces/16;
int ounces = totalounces - (16*pounds);
wt.w1 = pounds;
wt.w2 = ounces;
return wt;
}

void display(weight wt)
{
cout<<"The weight is "<<wt.w1<<" pounds and "<<wt.w2<<" ounces."<<endl;
}

void main()
{
clrscr();
char ans;
weight wt;
while(ans != 'n')// !! ans != 'N')
{
wt = take();
wt = calculate(wt);
display(wt);
cout<<"want to continue(y/n):";
cin>>ans;

}
getch();
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Need help with this conversion program

 
0
  #6
Dec 1st, 2004
  1. #include<iostream.h>
Don't use that. It's 10 years out of date (I know, the oldest book that lists the proper way is about 10 years old).

  1. void main()
Don't use, it's an abomination.

And lastly, don't do peoples' homework for them. It teaches them not to think and to be lazy and never learn the craft.
I don't want lazy poorly trained people as my future colleagues, it means I'll be doing more overtime doing their work and correcting their mistakes while they sit at home watching Wheel Of Fortune...
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 4
Reputation: kama is an unknown quantity at this point 
Solved Threads: 0
kama kama is offline Offline
Newbie Poster

Re: Need help with this conversion program

 
0
  #7
Dec 1st, 2004
ok this is what I did. I just made myself a pseudocode (basically the layout of the program) if you know what it is. Tell me if this is a the right idea.

#include <iostream>
using namespace std;


void input;

void calculate;

void output;

//main function
int main ()
{

input()

}


int input()
{
int pounds;
int ounces;

//get pounds from user
pounds = whatever the user entered for pounds

//get ounces from user
ounces = whatever user entered for ounces

//call the calculate function with the pounds and ounces
calculate(pounds, ounces)

}

int calculate(int pounds, int ounces)
{
int kilograms;
int grams;

kilograms = pounds / 2.2046


output(kilograms, grams)

}

int output(int kilograms, int grams)
{

cout kilograms

count grams

}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need help with this conversion program

 
0
  #8
Dec 1st, 2004
For pseudocode it looks like you're on the right track. [For actual code, there are a number of syntactical issues.]

But what are you doing with ounces? You ask for it, but never use it. Similarly, are you planning to do something with grams?

Please learn to use [CODE][/CODE] tags.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 140
Reputation: anastacia is an unknown quantity at this point 
Solved Threads: 1
anastacia's Avatar
anastacia anastacia is offline Offline
Junior Poster

Re: Need help with this conversion program

 
0
  #9
Dec 1st, 2004
hi well first of let me see if got ur question right.
u need to input a weight value in kilograms and in grams separately and give the corresponding output in pounds and ounces right. well if so just 4 get the loop 4 the time being. i would suggest that u concentrate on input process and output. this is wat i think should be done

#include<iostream.h>
#include<conio.h>
#include<math.h>
#define pound 2.0246;
void main()
{
int kilo,gram,pound=1,ounce=1;
int answerp,answero;

// inputing data
cout<<" Please enter the weight in kilos: ";
ciin>>kilo;
cout<<" Please enter the grams: ";
cin>>gram;

// convert kilo and gram into pound and ounces
answerp=kilo*pound;
answero=( gram*16*pound)/1000;
// this will compute data separately for the kilo part and gram part
// to display them saparately
cout<<kilo<<" is valued to" <<answerp"pounds"<<endl;
cout<<gram<<" is valued to" <<answero<<ounces"<<endl;
getch();
}
this should work
1 more tip always do ur program part by part
hope that it will work
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 4
Reputation: kama is an unknown quantity at this point 
Solved Threads: 0
kama kama is offline Offline
Newbie Poster

Re: Need help with this conversion program

 
0
  #10
Dec 1st, 2004
ok this is where I am now.

  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void InputWeight(int kilograms,
  6. int grams);
  7.  
  8. void CalculateWeight(int kilograms,
  9. int grams,
  10. int pounds,
  11. int ounces);
  12.  
  13. void OutputWeight(int pounds,
  14. int ounces);
  15.  
  16. /***************************Main Function**********************************/
  17. int main()
  18. {
  19.  
  20. int grams;
  21. int kilograms;
  22. int pounds;
  23. int ounces;
  24. char userChoice;
  25.  
  26. do
  27. {
  28.  
  29.  
  30. InputWeight(kilograms,grams);
  31.  
  32. CalculateWeight(kilograms,grams,pounds,ounces);
  33.  
  34. OutputWeight(pounds,ounces);
  35.  
  36. cout <<"Calculate another weight? (Y/N): ";
  37. cin >> userChoice;
  38.  
  39. }
  40. while ((userChoice == 'Y') || (userChoice == 'y'));
  41.  
  42.  
  43. return 0;
  44. }
  45. //call the input function
  46. void InputWeight(int kilograms,
  47. int grams)
  48. {
  49.  
  50. cout <<"Enter your weight for Kilograms: ";
  51. cin >> kilograms;
  52. cout<<"Enter your weight for Grams: ";
  53. cin >> grams;
  54. }
  55.  
  56. //call the calculate function with the pounds and ounces
  57. void CalculateWeight(int kilograms,
  58. int grams,
  59. int pounds,
  60. int ounces)
  61. {
  62. pounds=kilograms*pounds;
  63. ounces=(grams*16*pounds)/1000;
  64. }
  65.  
  66. //call the output function
  67. void OutputWeight(int pounds,
  68. int ounces)
  69. {
  70.  
  71. cout <<"Your weight conversion to pounds is: "<<pounds<<endl;
  72. cout <<"Your weight conversion to ounces is: "<<ounces<<endl;
  73.  
  74.  
  75. }

I still am confused of what calculations I need to use to convert the weights.......
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC