Need help writing a function.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gator6688
    New Member
    • Sep 2007
    • 63

    #16
    Could you please give me an example of declaring a function.

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #17
      You've already declared your functions:

      [CODE=cpp]void enterData(strin g Date, string FirstName, string LastName, double amount);[/CODE]

      Thia is an example of declaring a function. You have to define it now:

      [CODE=cpp]void enterData(strin g Date, string FirstName, string LastName, double amount) {
      // Your code here.
      }[/CODE]

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #18
        Could you please give me an example of declaring a function.
        We could, but we won't. We're here to help you learn, but if you need us to show you how to declare a function, the problem is you just aren't doing the necessary reading. If you are struggling with writing functions, I suggest reading some online tutorials (preferably the ones at cplusplus.com or cprogramming.co m or your textbook).

        Comment

        • gator6688
          New Member
          • Sep 2007
          • 63

          #19
          How long would it take you to write this program?

          Comment

          • gator6688
            New Member
            • Sep 2007
            • 63

            #20
            Plus, all the tutorials I read is for a function adding two intergers a+b which is easy. I have to be able to input the info into one function and have it passed on to another and have it displayed in the check. Yes for most of you it would probably be easy but I have only been learning C++ for 5 weeks and most of this stuff is still difficult for me.

            Comment

            • gator6688
              New Member
              • Sep 2007
              • 63

              #21
              Somebody please put me out of my misery and write this for me. Please.

              Comment

              • Ganon11
                Recognized Expert Specialist
                • Oct 2006
                • 3651

                #22
                The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

                Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

                Then when you are ready post a new question in this thread.

                MODERATOR

                We've given you a lot of help so far. You've got the code in your function! You've already written the majority of your program! All you need to do is copy and paste the relevant code and put it in the correct function - as we've already demonstrated. There is nothing else we can do for you.

                Comment

                • gator6688
                  New Member
                  • Sep 2007
                  • 63

                  #23
                  How can I get the data I enter to be sent to the check? Also, how come when it asks me for the first and last name and amount it all goes on the same line?

                  Code:
                  #include "stdafx.h"
                  #include <iostream>
                  #include <string>
                  using namespace std;
                  
                  string todaysDate;
                  string firstName;
                  string lastName;
                  double amount;
                  
                  void enterData();
                  void printCheck();
                  
                  
                  int _tmain(int argc, _TCHAR* argv[])
                  
                  {
                  	enterData();
                  	printCheck();
                  
                  	return 0;
                  }
                  
                  void enterData()
                  {
                  
                  
                      cout << "Enter today's date: ";
                  	cin  >> todaysDate;
                  	cout << "Enter the first name: ";
                  	cin  >> firstName;
                  	cout << "Enter the last name: ";
                  	cin  >> lastName;
                  	cout << "Enter the amount: ";
                  	cin  >> amount;
                  }
                  
                  void printCheck()
                  {
                      cout << "Zzyz Corp                                      Date: (today's date)"<<endl;
                  	cout << "1164 Sunrise Avenue                                        "<<endl;
                  	cout << "Kalispell, Montana\n                                         "<<endl;
                  
                  	cout << "Pay to the order of: (string firstName lastName)      $ (amount)\n "<<endl;
                  	
                      	
                  
                  	cout << "UnderSecurity Bank                                         "<<endl;
                  	cout << "Missoula, MT                                               "<<endl;
                  	cout << "                                                ____________________"<<endl;
                  	cout << "                                                Authorized Signature";
                  
                  	cout << endl << endl;
                  	
                  }

                  Comment

                  • sicarie
                    Recognized Expert Specialist
                    • Nov 2006
                    • 4677

                    #24
                    Originally posted by gator6688
                    How can I get the data I enter to be sent to the check?
                    You declare check to be void check() - so you're not passing anything to it, and you are not returning anything from it. You need to pass it the relevant variables, and return the relevant type.
                    Originally posted by gator6688
                    Also, how come when it asks me for the first and last name and amount it all goes on the same line?
                    Because you haven't told it not to. I would recommend putting a newline characters around what you want to be on a different line. The newline char is '\n', and can be incorporated into any string to create a new line.

                    Comment

                    Working...