Help please with function program.

This is a discussion on Help please with function program. within the C++ Programming forums, part of the General Programming Boards category; I am rather new to C++ and I have to write a program that will accept data for today's date, ...

Help please with function program.

I am rather new to C++ and I have to write a program that will accept data for today's date, first name, last name, and amount to an enterData() function and pass it to a printCheck() function. Then I need it to display in the correct spots on a check. I am stuck and am not really sure what to do next. Please help.

You need a method to preserve the data entered in the enterData function so that it can later be displayed in the printCheck function. You can do this best by declaring the variables in the main function and passing them (by reference) into the enterData function. Any changes made to them in that function will be reflected in the values the variables have in the main function. Then you can again pass them to the printCheck function so they can be output.

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens

I don't know what's wrong with your code, but the style is horrible. If you are going to use C++ you should learn how to use it right.

In this case it means learning how to put data into a class instead of using global variables. Global variables are generally considered a bad thing and should be avoided.

The way to do it is this:
Your program deals with one thing: a check.
With this check it does two things: it reads the data, and it prints the check.
These two actions are properly viewed as features of the check. As such they should be made into methods of a check object that you create.

So you need to learn how to use classes (objects), meathods(functions belonging to classes), and how to store data in classes.

cin beaks up input according to whitespace (tabs, spaces, newlines). So If you enter "Sept. 30, 2007", only "Sept." gets stored into the todaysDate variable. And "30," and "2007" get stored into firstName and lastName (respectively). So it should be no surprise that you are getting weird output. What you need to do is change:

Code:

cin >> todaysDate ;

Into:

Code:

getline(cin,todaysDate);

This will read an entire line of input (up to the newline) and store it into todaysDate.

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens