Results 1 to 5 of 5

Thread: My table program

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    NY State
    Posts
    145

    My table program

    // formatted output with cout and manipulators
    #include <iostream.h>
    #include <iomanip.h>
    int main()

    {

    float principal;
    float payment = 2000;
    float rate;
    int month = 0;
    float remainder = (principal*rate)-payment;


    cout << "Enter your principal: $";
    cin >> principal;
    cout << "Enter your rate: ";
    cin >> rate;
    cout << endl;
    cout << "----------------------------------";
    cout << endl;
    cout << endl;

    cout << setw(12) << "\nMonth" << setw(11) << "\nPayment" << setw(12) <<"\nRemainder\n";
    cin >> remainder;
    cout << setiosflags(ios::left)
    << setw(12) << ++month
    << setw(12) << payment
    << setw(12) << remainder;

    cout << "\n\n";
    return 0;
    }


    It says that my two local variable are not being initlaized.

    Can soembody take a look at it and see what is wrong

    Whiel you are looking at it
    A user can enter any principal or payemtn or rate
    but the mothns increase by one and the payment stays the same but the remainder changes

    Alsothis program is suppose to output one line at a time and the next tiem the user presses any key it goes to the next line until it has completed the cxycle of 35 months.

    Can anybody help me fix my mistakes!
    ICQ = 20476917
    AIM = Butnud

    Lets Talk!

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    NY State
    Posts
    145
    --------------------Configuration: table - Win32 Debug--------------------
    Compiling...
    table.cpp
    C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(33) : error C2374: 'month' : redefinition; multiple initialization
    C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(16) : see declaration of 'month'
    C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(35) : error C2061: syntax error : identifier 'payment'
    Error executing cl.exe.

    table.obj - 2 error(s), 0 warning(s)

    Here is my latest code
    I still get 2 errors and 1 warning

    // formatted output with cout and manipulators
    #include <iostream.h>
    #include <iomanip.h>
    float repayment(float);

    int main()

    {

    float principal;
    float payment = 2000;
    float rate;
    int month = ++month;
    float remainder = (principal*rate)-payment;

    cout << "Enter your principal: $";
    cin >> principal;
    cout << "Enter your rate: ";
    cin >> rate;
    rate / 100;
    rate += 1; //it should be > 1, so remaining increases
    cout << endl;
    cout << "----------------------------------";
    cout << endl;
    cout << endl;
    cin >> remainder;
    cout << setiosflags(ios::left)
    << setw(12) << ++month
    << setw(12) << payment
    << setw(12) << remainder;
    for (int month=1; month <= 35; month++){
    remainder *= rate;
    if payment=remainder; //repay exactly to $0

    cout << setw(12) << "\nMonth" << setw(11) << "\nPayment" << setw(12) <<"\nRemainder\n";
    }

    cout << "\n\n";
    return 0;
    }
    Last edited by Butnud; Mar 13th, 2002 at 05:08 PM.
    ICQ = 20476917
    AIM = Butnud

    Lets Talk!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    NY State
    Posts
    145

    update

    // Rob Gross
    // 3-13-02
    // CS 170

    #include <iostream.h>
    #include <iomanip.h>
    float repayment(float);

    int main()

    {

    float principal;
    float payment;
    float rate;
    int month = ++month;
    float remainder = (principal*rate)-payment;

    cout << "Enter your principal: $";
    cin >> principal;
    cout << "Enter your rate: ";
    cin >> rate;
    rate = rate/100;
    rate += 1; //it should be > 1, so remaining increases
    cout << endl;
    cout << "----------------------------------";
    cout << endl;
    cout << endl;
    cout << setiosflags(ios::left)
    << setw(12) << ++month
    << setw(12) << payment
    << setw(12) << remainder;
    for (month=1; month <= 35; month++){
    remainder *= rate;

    cout << setw(12) << "\nMonth" << setw(11) << "\nPayment" << setw(12) <<"\nRemainder\n";
    }

    cout << "\n\n";
    return 0;
    }


    --------------------Configuration: table - Win32 Debug--------------------
    Compiling...
    table.cpp
    C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(16) : warning C4700: local variable 'month' used without having been initialized
    C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(17) : warning C4700: local variable 'principal' used without having been initialized
    C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(17) : warning C4700: local variable 'rate' used without having been initialized
    C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(17) : warning C4700: local variable 'payment' used without having been initialized

    table.obj - 0 error(s), 4 warning(s)
    ICQ = 20476917
    AIM = Butnud

    Lets Talk!

  4. #4
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    you haven't given any value to principal, payment, or rate before you use them in the expression that initialiizes remainder

    the same with month
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    NY State
    Posts
    145
    okay now my problem is this

    My first line of the table does not line up and 2 I can't get the next month to find the new remainder
    what I wanna do is take the principal of the next month and * rate then - the payment to get a new number.

    I don't know what I am missing and i want it to go until it hits the 35th month.

    Here is my code
    // Rob Gross
    // 3-13-02
    // CS 170

    #include <iostream.h>
    #include <iomanip.h>
    float repayment(float);

    int main()

    {

    float principal;
    float payment = 0;
    float rate = 0;
    float month = +1;
    float remainder = 1;

    cout << "Enter your principal: $";
    cin >> principal;
    cout << "Enter your payment: $ ";
    cin >> payment;
    cout << "Enter your rate: ";
    cin >> rate;
    rate = rate/100;
    rate += 1; //it should be > 1, so remaining increases
    cout << endl;
    cout << "----------------------------------";
    cout << endl;
    cout << endl;

    for (month=1; month <= 35; month++){
    remainder = (principal*rate)-payment;

    cout << setw(12) << "\nMonth" << setw(11) << "Payment" << setw(12) <<"Remainder\n";
    cout << setiosflags(ios::left)
    << setw(12) << month
    << setw(12) << payment
    << setw(12) << remainder;
    }

    cout << "\n\n";
    return 0;
    }
    ICQ = 20476917
    AIM = Butnud

    Lets Talk!

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