what's wrong with my pointer?

This is a discussion on what's wrong with my pointer? within the C++ Programming forums, part of the General Programming Boards category; /* Calculate the total charges and the total hours for the parking garage. */ #include <iostream> using std::cout; using std::cin; ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    19

    what's wrong with my pointer?

    /* Calculate the total charges and the total hours for the
    parking garage. */

    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    #include <iomanip>

    using std::setw;

    double calculateCharges ( double );

    int main ()
    {
    double a;
    double b;
    double c;
    double totalcharges;

    cout << "Enter the number of hours for CAR 1:";
    cin >> a;

    cout << "Enter the number of hours for CAR 2:";
    cin >> b;

    cout << "Enter the number of hours for CAR 3:";
    cin >> c;

    cout << "CAR:" << setw( 10 ) << "HOURS:" << setw( 15 )
    << "CHARGES:\n";

    cout << " 1 " << setw( 10 ) << a << setw( 10 )
    << calculateCharges( a ) << "\n";
    totalcharges += calculateCharges( a );

    cout << " 2 " << setw( 10 ) << b << setw( 10 )
    << calculateCharges( b ) << "\n";
    totalcharges += calculateCharges( b );

    cout << " 3 " << setw( 10 ) << c << setw( 10 )
    << calculateCharges( c ) << "\n";
    totalcharges += calculateCharges( c );

    cout << "TOTALS:" << setw( 6 ) << a + b + c << setw( 10 )
    << totalcharges << endl;

    return 0;
    }

    double calculateCharges ( double hours )
    {
    double charges = 0.0;
    couble *chargesPtr;
    *chargesPtr = &charges;

    if ( hours <= 3)
    charges = 2.00;
    else
    if ( hours >= 16 )
    charges = 10.00;
    else
    charges = 2.00 + ( ( hours - 3 ) * 0.50 );

    return *chargesPtr;
    }

  2. #2
    Unregistered
    Guest
    *chargesPtr = &charges;
    should change to :
    *chargesPtr = charges;

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Why do you want to use a pointer?

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    i think its the couble *chargesPtr; ///i think
    //u meant double!?

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Change your line...
    *chargesPtr = &charges;

    to this line...
    chargesPtr = &charges;

    you don't want the value of chargesPtr to be a memory address.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 03:29 PM
  3. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 02:00 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 04:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM

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