quite newbish program not working

This is a discussion on quite newbish program not working within the C++ Programming forums, part of the General Programming Boards category; someone please help, ive only been programming for a few days and saw something similar in a tutorial i read ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    5

    quite newbish program not working

    someone please help, ive only been programming for a few days and saw something similar in a tutorial i read and thought id try it but it wont out put anything

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int monthlyexpenses = 300 + 200 + 75;
        int monthlyincome = 1000;
        float monthlyinterest = .02;
        float total = 0;
        float x = total;
        float interestearned = 0;
        for (x = 1; x <= 12;)
            interestearned = monthlyincome * monthlyinterest;
            total = total + interestearned + monthlyincome - monthlyexpenses; {
                  cout<< total <<endl;
                  }
    }

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    You never change the value of x.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Location
    Canada
    Posts
    80
    Code:
    for (x = 1; x <= 12;)
    The for-loop is incomplete. make it e.g. for (x = 1; x <= 12; x++)

  4. #4
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Posts
    320

    Another thing

    [QUOTE=littlelefty7]someone please help, ive only been programming for a few days and saw something similar in a tutorial i read and thought id try it but it wont out put anything

    Code:
        float x = total;
        for (x = 1; x <= 12;)
    Why set X to total when on almost the very next line you set it to 1? Also, I'm assuming x is the number of months (because of 1 to 12 loop) so it doesn't make much sense to set the month number to a dollar value. Also, x is a floating point and you should be using an int type for a loop counter.

  5. #5
    xhi
    xhi is offline
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    get rid of.
    float x = total;

    do this
    Code:
    for(int i=0; i<12; ++i) {
    ...
    }
    this will give you your 12 loops..

    if that example you posted is the style of the tutorial, then find new tutorials..

    there are plenty of tuts on this site..

    <unrelated> wow! forcing to use code tags now.. Excellent!

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    5
    thanks for all the help like ive said ive only been programming for a few days and i dont quite konw what im doing yet. the entire program wasnt on the tutorial just part of it and i tried to make the rest. thanks for the help, by the way i got it to work.
    Last edited by littlelefty7; 02-18-2006 at 11:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Replies: 5
    Last Post: 02-02-2003, 09:56 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  4. Simple Program not working right (in C)
    By DruzeTito in forum C Programming
    Replies: 5
    Last Post: 06-01-2002, 10:14 PM
  5. Program ive been working on called ChatMate
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-23-2002, 08:05 PM

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