C++ help. Absolute beginner - simple program.

jimbo118

Newbie
Joined
Nov 22, 2004
Messages
8,793
Reaction score
0
Alright, I need to do this:

'Write a program that converts kg, pounds, stone into one another.

The program should ask the user to choose the unit to convert from, and the unit to convert into, then should ask for the amount to convert, and return the result of the conversion onto the screen.'

Could someone help me, plox.
 
I don't know anything about C++, but even if I did, I wouldn't be able to help you without some more information on what you do know how to do and what you're stuck with. If this is for a class, shouldn't you have some knowledge as to how to write the program? The conversion aspect is simple math, and the rest is just prompting the user for a variable input. Is this a command line program, or like a windows interface with text boxes and buttons?
 
What do you have so far? If you are asking people to write this for you that is frowned upon in this establishment, as it should be.
 
How does c++ differ from c, I could write a c program for it, but I've never used c++
 
I think the syntax is pretty similar between c and c++, i know a little c++, and from what I've seen with c, they look fairly similar.

I agree with what No Limit said, show what you have so far, then ask for input, not to have others write you program for you.
 
Basically just change your I/O from scanf/printf to using the standard library stuff cin/cout
 
This is pretty simple and I barely remember c++. You just ask them for a selection... 1 for lb to kg or 2 or kg to lb I guess... take the "cin" and multiply/divide it by 2.2 and "cout".

I doubt I could remember enough C++ to do it. These days I'd use C# in asp.net and be able to do it faster in a much friendlier interface with buttons and hot sex. Actually I'd use VB.net but using C# would be virtually the same and just as easy.

Edit: oh yeah you need an if statement in there to pick which conversion btw...
 
How does c++ differ from c, I could write a c program for it, but I've never used c++

The syntax is very similar and many functions work exactly the same. But C++ is a object oriented language right out of the box, whereas C is not.
 
Short of writing the program, I dont really have much to add. Start by writing some pseudocode out to help isolate what problems you are having.
 
I can do it in Javascript if that helps.



It doesn't ;(
 
Thanks for the replies.

Just submitted it. The programme admin was still online. Weird, dunno why he's checking the moodle site at this time. He said the programme ran for him and it was all correct. First type of any programming I ever did. It's pretty simple. I think I did it kinda arseways but w/e. Too embarassed to post it coz you'll prolly all raff at my rubbish program :eek:

Anyway, this can be closed if an admin deems it so.
 
Alright, I need to do this:

'Write a program that converts kg, pounds, stone into one another.

The program should ask the user to choose the unit to convert from, and the unit to convert into, then should ask for the amount to convert, and return the result of the conversion onto the screen.'

Could someone help me, plox.

Does this in any way involve the hot blond medical type you were talking to me about yesterday?
 
Thanks for the replies.

Just submitted it. The programme admin was still online. Weird, dunno why he's checking the moodle site at this time. He said the programme ran for him and it was all correct. First type of any programming I ever did. It's pretty simple. I think I did it kinda arseways but w/e. Too embarassed to post it coz you'll prolly all raff at my rubbish program :eek:

Anyway, this can be closed if an admin deems it so.

Don't be a vagina, post your code.
 
No, I haveto do 10 credits of electives as part of my Bsc in Radiography each year. I did the structured elective 'computer programming for radiography'. It's actually just the 'introduction to comp programming I' course for the comp science students but we probably haveto do some special assignment later. I only did it coz I thought it'd look better on the cv that I stayed within programme for electives rather than doing something random like arabic.

Plus if I do it up to year 3 I would get a minor in comp programming for radiography on my degee statement along with my bsc in radiography.

Seeing, the med student later :D

Don't be a vagina, post your code.
I can probably simplify it alot but I just tried to copy the few examples I know. Aslong as it runs I dont care atm.

k

/*
This program converts Kgs to Pounds(0), Pounds to Kgs(1), Kgs to Stone(2), Stone to Kgs(3), Pounds to Stone(4), and Stone to Pounds(5)
*/

#include <iostream>

using namespace std;

int main()
{
double k; //here go Kilograms
double p; //here go Pounds
double s; //here go Stone
int choice;

cout << "Convert Kgs to Pounds (enter 0) or Pounds to Kgs (enter 1) or Kgs to Stone (enter 2) or Stone to Kgs (enter 3) or Pounds to Stone (enter 4) or Stone to Pounds (enter 5): ";
cin >> choice;

if (choice==0) {
cout << "Enter the weight in Kgs: ";
cin >> k;
cout << k << "Kgs = " << k * 2.20462262 << "Pounds\n";
}
if (choice==1) {
cout << "Enter the weight in Pounds: ";
cin >> p;
cout << p << "Pounds = "<< p * 0.45359237 << "Kgs\n";
}
if (choice==2) {
cout << "Enter the weight in Kgs: ";
cin >> k;
cout << k << "Kgs = "<< k * 0.157473044 << "Stone\n";
}
if (choice==3) {
cout << "Enter the weight in Stone: ";
cin >> s;
cout << s << "Stone = "<< s * 6.35029318 << "Kgs\n";
}
if (choice==4) {
cout << "Enter the weight in Pounds: ";
cin >> p;
cout << p << "Pounds = "<< p * 0.0714285714<< "Stone\n";
}
if (choice==5) {
cout << "Enter the weight in Stone: ";
cin >> s;
cout << s << "Stone = "<< s * 14 << "Pounds\n";
}
return 0;

}
 
Thanks for the replies.

Just submitted it. The programme admin was still online. Weird, dunno why he's checking the moodle site at this time. He said the programme ran for him and it was all correct. First type of any programming I ever did. It's pretty simple. I think I did it kinda arseways but w/e. Too embarassed to post it coz you'll prolly all raff at my rubbish program

Anyway, this can be closed if an admin deems it so.
What? Do it.

We'll make you a programming god. Or at least a little better.
 
Back
Top