i am using visual basic console application to create programs and here is the question.

1. A program is required for a grocer that will add two weights together (in pounds and ounces). The program should also convert the total weight to a value in kilograms.

Use three functions.

Function 1: allows the user to enter the name of the produce, and the weights in pounds and ounces, which are validated and stored..

Function 2: calculates the total weight in pounds and ounces and converts that to kilograms.

Function 3: displays the name of the produce, the total weight in pounds and ounces and the total weight in kilograms.

Think about function 2 and the actual values that will be returned from this function.

The user should be given an option to convert another weight or end the program

Note: there are 16 ounces in one pound, and there are 0.454 kilograms in one pound.
[/CODE]
HERE ISTHE WHAT I HAVE DONE SO FAR IS THIS RIGHT

``````        string product;
Single weightp = 0f;
Single weighto= 0f;
Single convertp= 0f;
Single ptokilo = 0.45359237f;
Single converto= 0f;
Single otokilo = 0.0283495231f;
Single totalkiloweight = 0f;

Console.WriteLine("the name of the produce");

Console.WriteLine("Enter weight in poounds");

Console.WriteLine("Enter weight in Ounces");

convertp = weightp * ptokilo;

Console.WriteLine("Here is pounds converted to kilograms");
Console.WriteLine(convertp);

converto = weighto * otokilo;

Console.WriteLine("Here is Ounces converted to kilograms");
Console.WriteLine(converto);

totalkiloweight = converto + convertp;

Console.WriteLine("Here is the total Weight in Kilograms for the two weights");
Console.WriteLine(totalkiloweight);

``````

i have feeling the question does not sya o convert the pound and oucnes to kilograms but i think it means to say it convert pounds to oucnes then convert this answer to kilograms which is correct??

## All 3 Replies

To me it does not matter how many pounds and ounces you have.
Just use the right conversion factor to convert them to kilos.
Your assignment states you have to use functions.
C# has only notion of methods, but you could call a method that returns a value a function.
Here is one:

``````static Single PoundsToKilo(Single pounds)
{
// convert pounds to kilo
return 0.45359237f * pounds;
}``````

The qustion seems a little ambiguous, i would check a few points with your lecturer.
Primarily, 'Function' is a very ambiguous term:
- in plain English it means a role or purpose for an object.
- in a proceedural coding paradigm a 'Function' is a named code block which returns a value, these are usually maintained seperately from the main program code. However, C# is an object oriented paradigm, and since all code exists as a member of a class object there are no functions, only methods.

There is a reason for the ramble ;)
Due to the way OO languages have grown out of proceedural ones, there are a few terms which are still used; many people still refer to a method which returns a value as a 'function'.

This question could be answered very simply in the way you have started, read in the values, perform the calculations, output the results. If he has used the term function purely in its english meaning then you have met the requirements. If he means function in terms of "a method which returns a value" then you will need to restructure your code.

Sorry for the long post, but i wouldnt want to give advice based on an incorrect assumption, and i figured a little background would help you to understand what i'm asking.

Also, 'produce' could be either singular or plural (also a noun or a verb, god bless the english language). Check if you have to accept a name and weight for two different products (eg Name1, Weight1, Name2, Weight2) or one name with two weights (eg Name, Weight1, Weight2).

lol..ddanbe posted 13 mins before me, but i started writing that before he posted : / So much for "Post Quick Reply" haha.

He makes the same point, i just clarified it. You will need to learn how to use methods as you learn more of the C# langauge, but i wouldnt pressume to teach you faster than your lecturer ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.