CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Apr 2009
    Posts
    11

    Arrow Homework Function Help.

    Below i Have 3 different functions I wrote for a homework assignment. I'm not sure what is wrong with them. Any help would be GREATLY Appreciated.

    void airfare(double &airfareCost, double &airfareAllowd)
    {
    Cout<< "Enter cost of airefare"<<endl;
    cin>> airfareCost<<endl;
    airfareAllowd=airfareCost;

    }


    void milage(int miles, double &milageCost, double&milageAllowd)
    {
    cout<< "Enter cost of airefare"<<endl;
    cin>> milageCost<<endl;
    cout<<"Enter number of miles"<<endl;
    cin<<miles<<endl;
    milageAllowed= miles* 0.38 ;
    }


    Void taxi(int taxiDays, double &taxiCost, double&taxiAllowd)
    {
    cout<< "Enter number of days travelled"<< endl;
    cin>>taxiDays<<endl;
    cout<< "Enter Total cost of Taxi"<<endl;
    cin>>taxiCost<<endl;
    taxiAllowed=taxiDays * 10 ;
    }
    Last edited by Poeticsoul44; April 27th, 2009 at 09:47 AM.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Homework Function Help.

    C++ is case sensitive.

    Pay attention to the direction when using << and >>.

    Use whitespace for improved readability.

  3. #3
    Join Date
    Apr 2009
    Posts
    11

    Re: Homework Function Help.

    So I messed up on << and >>? Was that the only thing?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Homework Function Help.

    Quote Originally Posted by Poeticsoul44 View Post
    So I messed up on << and >>? Was that the only thing?
    I don't do a lot of console programming, but I'm not sure sending endl to cin makes any sense.

    I also mentioned that C++ is case sensitive.

  5. #5
    Join Date
    Apr 2009
    Posts
    11

    Re: Homework Function Help.

    Yea. I caught the error..But theres something else wrong with it because they wont compile for some reason.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Homework Function Help.

    Quote Originally Posted by Poeticsoul44 View Post
    Yea. I caught the error..But theres something else wrong with it because they wont compile for some reason.
    There are lots of errors. I already pointed out the category. What does the compiler say?
    Last edited by GCDEF; April 27th, 2009 at 10:49 AM.

  7. #7
    Join Date
    Apr 2009
    Posts
    11

    Re: Homework Function Help.

    the first gives the following errors:
    air.cpp: In function &#226;void airfare(double&, double&)&#226;:
    air.cpp:3: error: &#226;cout&#226; was not declared in this scope
    air.cpp:3: error: &#226;endl&#226; was not declared in this scope
    air.cpp:4: error: &#226;cin&#226; was not declared in this scope
    air.cpp:5: error: &#226;airefareAllowed&#226; was not declared in this scope
    air.cpp:5: error: &#226;airefareCost&#226; was not declared in this scope

    The second funtion i get these errors:
    miles.cpp: In function &#226;void milage(int, double&, double&)&#226;:
    miles.cpp:3: error: &#226;cout&#226; was not declared in this scope
    miles.cpp:3: error: &#226;endl&#226; was not declared in this scope
    miles.cpp:4: error: &#226;cin&#226; was not declared in this scope

    And the third gives me these errors:
    taxi.cpp: In function &#226;void taxi(int, double&, double&)&#226;:
    taxi.cpp:3: error: &#226;cout&#226; was not declared in this scope
    taxi.cpp:3: error: &#226;endl&#226; was not declared in this scope
    taxi.cpp:4: error: &#226;cin&#226; was not declared in this scope
    [wm136158@adanew ~]$

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Homework Function Help.

    Did you include iostream?

  9. #9
    Join Date
    Apr 2009
    Posts
    11

    Re: Homework Function Help.

    I just did and i get these errors for the first:
    air.cpp: In function &#226;void airfare(double&, double&)&#226;:
    air.cpp:4: error: &#226;cout&#226; was not declared in this scope
    air.cpp:4: error: &#226;endl&#226; was not declared in this scope
    air.cpp:5: error: &#226;cin&#226; was not declared in this scope
    air.cpp:6: error: &#226;airefareAllowed&#226; was not declared in this scope
    air.cpp:6: error: &#226;airefareCost&#226; was not declared in this scope


    For the second i get:
    miles.cpp: In function &#226;void milage(int, double&, double&)&#226;:
    miles.cpp:4: error: &#226;cout&#226; was not declared in this scope
    miles.cpp:4: error: &#226;endl&#226; was not declared in this scope
    miles.cpp:5: error: &#226;cin&#226; was not declared in this scope

    and the third i get:
    taxi.cpp: In function &#226;void taxi(int, double&, double&)&#226;:
    taxi.cpp:4: error: &#226;cout&#226; was not declared in this scope
    taxi.cpp:4: error: &#226;endl&#226; was not declared in this scope
    taxi.cpp:5: error: &#226;cin&#226; was not declared in this scope

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Homework Function Help.

    Post your entire code as it is now.

  11. #11
    Join Date
    Apr 2009
    Posts
    11

    Re: Homework Function Help.

    First function code:
    #include <iostream>
    void airfare(double &airfareCost, double & airfareAllowed)
    {
    cout<< "Enter cost of airfare"<<endl;
    cin>>airfareCost;
    airefareAllowed=airefareCost;
    }

    2nd:
    #include <iostream>
    void milage(int miles,double &milageCost, double&milageAllowed)
    {
    cout<<"Enter cost of milage"<<endl;
    cin>>milageCost;
    cout<<"enter number of mile"<<endl;
    cin>>miles;
    milageAllowed= miles * 0.38;
    }

    3rd:
    #include <iostream>
    void taxi(int taxiDays, double &taxiCost, double&taxiAllowed)
    {
    cout<< "Enter number of days travelled"<<endl;
    cin>>taxiDays;
    cout<<"enter total cost of taxi"<<endl;
    cin>>taxiCost;
    taxiAllowed=taxiDays *10;
    }

  12. #12
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Homework Function Help.

    You forgot to put
    Code:
    using namespace std;
    at the top.

    And there's no need to #include a file more than once in a given cpp.

  13. #13
    Join Date
    Apr 2009
    Posts
    11

    Re: Homework Function Help.

    I just included "using namespace std;" and get these errors:
    1st:
    air.cpp: In function &#226;void airfare(double&, double&)&#226;:
    air.cpp:7: error: &#226;airefareAllowed&#226; was not declared in this scope
    air.cpp:7: error: &#226;airefareCost&#226; was not declared in this scope
    2nd:
    miles.cpp: In function &#226;void milage(int, double&, double&)&#226;:
    miles.cpp:4: error: &#226;cout&#226; was not declared in this scope
    miles.cpp:4: error: &#226;endl&#226; was not declared in this scope
    miles.cpp:5: error: &#226;cin&#226; was not declared in this scope
    3rd:
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
    (.text+0x20): undefined reference to `main'
    collect2: ld returned 1 exit status

  14. #14
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Homework Function Help.

    You're going to have to give us more to work with if you want help sorting this out.....

  15. #15
    Join Date
    Apr 2009
    Posts
    11

    Re: Homework Function Help.

    What all do you want to know?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured