Function and Structures help!

Hello,

This is an example that I want to learn about functions and structures:

In the heydey of the British empire, Great Britain used a monetary system based on pounds, shillings, and pence with the following conversions:

1 pound = 20 shillings

1 shilling = 12 pence

The program should prompt the user to enter two currency values represented in £PP.SS.CC format (2 digits for pounds, 2 digits for shillings, and 2 digits for pence). Each element within a currency value can be entered separately without decimal points if you wish. Store each currency value in a structure with the following format:

struct Currency

{

int Pounds;
int Shillings;
int Pence;

};

Convert each currency value (pounds, shillings, pence) to total pence (type long int), add the two pence totals together and convert that sum back to the pounds-shillings-pence format shown above and display the result.


The pence value should not exceed 11. The shillings value should not exceed 19. The pounds value will be limited such that its value should not exceed 99. If any of these values do exceed the maximum value, they must wrap around to 0, etc.




The program must use the seven functions defined below with the exact names and prototypes given (any deviation will result in severe point reduction). A description follows each function prototype:

(1) void Input_Cur(Currency&);
Inputs the first currency value (pounds, shillings, pence) and returns it using a reference parameter.

(2) Currency Input_Cur();
Inputs the second currency value and returns it using the return statement.

(3) int Validate_Cur(Currency);
Accepts a currency value and returns a code indicating valid or invalid data.

(4) void Display_Cur(Currency);
Accepts a currency value (pounds, shillings, pence) fpr printing and returns nothing

(5) long Cur_To_Pence(Currency);
Accepts pounds, shillings, pence and returns the total equivalent pence

(6) Currency Pence_To_Cur(long);
Accepts total pence and returns a currency value in pounds, shillings, and pence.

(7) void Print_Zero(int);
Prints leading zeros if necessary. Accepts a pounds, shillings, or pence value, and prints a zero only if the value < 10. If the value passed is ≥ 10, nothing is printed. Called from Display_Cur().

The input and output dialogue should appear as follows:

Case 1

Enter Currency 1: 19 15 11

Enter Currency 2: 7 9 5

Currency 1: £19.15.11

Currency 2: £07.09.05

Result: £27.05.04

Case 2

Enter Currency 1: 3 12 16

Enter Currency 2: 43 18 7

Currency 1: £03.12.16

Currency 2: £43.18.07

Result: Invalid currency was entered



Case 3

Enter Currency 1: 0 0 1

Enter Currency 2: 99 19 11

Currency 1: £00.00.01

Currency 2: £99.19.11

Result: £00.00.00


For each case, print the two input values and the resulting sum in £PP.SS.CC format. When displaying the result, some compilers use the hex character constant ‘\x9c’ (decimal 156) to generate the pound symbol £. Generating the pound symbol, however, is not required.


Each pound, shilling, and penny value should be printed as two-digit values with zero fill for all values less than 10. Do not use the setfill manipulator; use the Print_Zero function to zero fill. Use no global variables. The Validate_Cur function should validate the input values and return a zero if the data are valid and a -1 if the data are invalid. If the data are invalid, print the currency value (pounds, shillings, and pence with decimal points) and an appropriate error message and continue with the next case; do not calculate the sum. Output all currency values using Display_Cur invoked from the main function.

Use a looping mechanism of your choice to process an arbitrary number of cases of data. Your program must work for error cases as well as valid cases. Error cases may include negative values and values that exceed the maximums.


and this is my code so far (I know it sucks...):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;

////////////////////////////////////////////////////////////////////////////////
struct Currency                                    //Old English monetary system
 {
   int Pounds;
   int Shillings;
   int Pence;
 };
////////////////////////////////////////////////////////////////////////////////
void Input_Cur(Currency&);


int main()
{
    Currency cur1, cur2;

    cout << "Enter Currency 1: ";  cin >> cur1.Pounds >> cur1.Shillings >> cur1.Pence;

    cout << "Currency 1: \x9c" << cur1.Pounds <<"."<< cur1.Shillings <<"."<< cur1.Pence;




}

 //----------------------------------------------------------------------------
 // void Input_Cur(Currency&);
 void Input_Cur(Currency&)
 {
   return ????

 }





The problem is that I don't have any knowledge about those topics, and I want to learn from this program. Doesn't seem to be be so difficult but I will take these program as a reference for future exercises. Thanks in advance for the help!
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/classes/

Note: Classes are the same as structs in C++, the only difference being:
1
2
3
4
5
6
7
8
struct Mystruct{
//...
};
//Is equivalent to:
class Myclass{
   public:
//...
};
^As a clarifying note to you jsch, Daleth's code verbally described may help as well. Hopefully Daleth doesn't care if I expand on their post.

Once you learn more about classes and the basics of them, this will make more sense, but:
A struct in C++ is a class, but everything in it -- variables and methods -- are all strictly public entities. That can be seen by line 6 in Daleth's code snippet where public: appears. This delineation is not important until you get more into Object-Oriented programming though.

If you don't have any experience in programming at all and want to learn, welcome to this incredibly wonderful and powerful tool. Ask some more questions about what you want to accomplish with this program, and also how you are confused by things, and I will try to answer you. A lot of people here aren't interested in spending time teaching someone how to program from the ground up because it can be tedious only through forums-like communication. I will try to help you out if you want, but some tutorials, books or even a programming class that has hands-on learning may be more helpful. Everyone learns differently though, so it's up to you.
Topic archived. No new replies allowed.