Problem with code. Need advice.

This is a discussion on Problem with code. Need advice. within the C++ Programming forums, part of the General Programming Boards category; I have an issue with some basic code I've been writing to learn C++. I've posted it here with comments. ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    Question Problem with code. Need advice.

    I have an issue with some basic code I've been writing to learn C++. I've posted it here with comments. I'm using Code::Blocks, if that helps, and if the formatting doesn't come out right in the post, you should be able to copy and paste it to a maximized notepad file to get the formatting right. Otherwise, I'll attach a .txt file to this post. Take your pick.

    Code:
    //This is a nonsensical program for me to practice various aspects of the C++ Language. It should
    //have a very simple conversation with the user. However, when I attempt to compile the program, I
    //get several error messages stating (for example):
    //  "error: too few arguments to function 'void DayMessage(std::string, std::string)'"
    //Please help me understand where I am going wrong, as I have looked over the code and cannot
    //understand the errors. Thank you. Replies can be posted here or sent to sdaniels1288@gmail.com.
    
    #include <iostream>
    
    using namespace std;
    
    //Just a simple function usage. Extraneous, I know, but my first self-created function.
    void HelloThere()
    {
        cout<<"\n\nWell, hello there!\n\n";
    }
    
    //Not extraneous. Should get a carriage return to pass to void PrgmEnd()
    void GetBreakCmd()
         {
            string BreakCmd="a"; //Initializes BreakCmd to 'a' so that Return must be pressed.
    
            cout<<"\n\n\nPlease press Return (Enter) to close.";
            cin>>BreakCmd;
         }
    
    //First instance of the above stated error. Should pass BreakCmd to the function, and if matching,
    //close down the program. Otherwise, it should repeat the prompt to press enter to close.
    void PrgmEnd(string BreakCmd)
    {
    
         if (BreakCmd == "")//In other words, if Return (Enter) was pressed
         {
            //Should exit the function and return to main, ending the program and closing the window.
         }
         else
         {
            GetBreakCmd(); //Go back and repeat the prompt
         }
    
    }
    
    //The next instance of the error. This function should test the string DayOfWeek, and output a
    //message based on the input. Doesn't have an error catcher for entries that are not days of the
    //week yet. Also likely has several other errors. Sorry, I know, but I was going to start debugging
    //when I hit this snag.
    void DayMessage (string DayOfWeek , string Name)
            {
                if (DayOfWeek == "Friday")
                {
                    cout<<"\nIt's Friday? Yay! That means it's payday!\n\n";
    
                }
                else if (DayOfWeek == "Saturday" || DayOfWeek == "Sunday")
                {
                    cout<<"\nAh, that's right! Payday was just here!\n\n";
                }
                else
                {
                    cout<<"\nDarn! It's not Friday... I guess payday isn't here yet.\n\n";
                }
    
                  cout<<"Anyway, "<<Name<<", I'm feeling pretty tired. I'm going to go to sleep now.\n\nGoodbye, "<<Name<<"!\n";
    
            }
    
    int main()
    {
        //Declares and initializes the two variables Name and DayOfWeek
        string Name="";
        string DayOfWeek="";
        
        //Executes that first simple function
        HelloThere();
    
        //Prompt for the user's name
        cout<<"\nWhat is your name?\n\n> ";
        cin>>Name;
    
        //Response and prompt for the day of the week
        cout<<"\nHello, "<<Name<<"! What day is today?\n\n> ";
        cin>>DayOfWeek;
        
        //Should rund DayMessage based on the entry for DayOfWeek
        DayMessage();
        
        //Should prompt and get the program close sequence
        GetBreakCmd();
        
        //If program close sequence is executed, should finish out the main function and close the
        //program.
        PrgmEnd();
        
        //Returns a 0. I know there's probably a different way of doing this, but this is how I've
        //learned so far. Any hints, tips, tricks, otherwise would be appreciated. I'm a greenhorn
        //programmer and willing to learn if you're willing to offer advice.
    	return 0;
    }
    
    //Thanks again for the help. Again, replies can be posted here or emailed to me at
    //sdaniels1288@gmail.com.
    Thanks again,

    Steve.
    Attached Files Attached Files
    Last edited by sdaniels1288; 05-31-2011 at 03:37 AM. Reason: Forgot to add the attachment

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Code:
       //Should rund DayMessage based on the entry for DayOfWeek
        DayMessage();
    Look at your function definition... it wants two strings, DayOfWeek and Name...

    Code:
    DayMessage(DayOfWeek,Name);
    C++ is smart but it's not a mind reader...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need advice to solve a problem
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 08-06-2009, 01:57 AM
  2. Advice sought on GUI library / tools / code
    By PaulBlay in forum C++ Programming
    Replies: 7
    Last Post: 06-03-2009, 03:20 AM
  3. Looking for a Code Management System. Advice needed.
    By Kempelen in forum Windows Programming
    Replies: 0
    Last Post: 04-23-2009, 10:06 AM
  4. Advice requested, Code makes sense to me, not compiler
    By andrew.bolster in forum C Programming
    Replies: 53
    Last Post: 01-06-2008, 12:44 PM
  5. Problem with this code
    By miclus in forum C++ Programming
    Replies: 9
    Last Post: 09-01-2004, 08:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21