Thread: Why does old code stay stuck in my console?

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    16

    Why does old code stay stuck in my console?

    Thank you in advance for your responses!

    I am using Dev compiler and compiled and ran my prog. I went back and changed some things, yet the changes don't show up, just the old code. What am I missing?



    Code:
    #include <stdio.h>
          #include <iostream>
    
    int addUP (int a, int b, int c)
     {return (a + b +c);}
    
    
    
     void main ()
    
    
     {
         //here is the first funciton call
       cout << "the first function is addition  " << addUP (3,4,12) << endl;
    
       int x = 12;
       int y = 25;
       int z = 140;
    
       //here is the 2nd call
    
       float average = addUP (x, y, z-20)/3;
       cout << " the average of "      << x << "  " << y << " and  " << z << " is  " << average;
    
    
    
    
    
      cin.get();
    
     return 0;
    }
    Last edited by LLINE; 11-12-2008 at 03:54 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Considering that the code doesn't compile without errors, I expect that the reason you are getting the old output because your old code is the latest you have successfully compiled.

    Don't feel bad about that, I've done it several times.

    Edit: Did you by any chance change from C to C++ in this project?

    --
    Mats
    Last edited by matsp; 11-12-2008 at 03:59 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    void main ()
    {
        ...
    
        return 0;
    }
    int main, not void main.

    Code:
    #include <stdio.h>
    It would be more consistent (in C++) to use <cstdio> instead of <stdio.h>.

    Code:
    float average = addUP (x, y, z-20)/3;
    cout << " the average of "      << x << "  " << y << " and  " << z << " is  " << average;
    Very confusing to the user, you are displaying the average x, y, z-20 but you are telling them the average is of x, y, z. If they try to do the math themselves as an error check (based on what you've told them you are averaging), they're going to be confused.

    Code:
    #include <iostream>
    
    ...
    
    cout << "the first function is addition  " << addUP (3,4,12) << endl;
    
    ...
    
    cout << " the average of "      << x << "  " << y << " and  " << z << " is  " << average;
    cout and endl are in the std namespace so you'd have to take that into account, so either:
    1. Write using namespace std; somewhere after your #include statements.
    2. Put using std::cout; using std::endl; statements somewhere before their use in your code.
    3. Preface all of those items with std:: in your code.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    However, stdio.h is not being referenced at all, so it could simply be removed altogether.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wrong/right ASCII?
    By stevesmithx in forum C Programming
    Replies: 13
    Last Post: 12-05-2008, 11:38 PM
  2. Problems with a simple console game
    By DZeek in forum C++ Programming
    Replies: 9
    Last Post: 03-06-2005, 02:02 PM
  3. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Stuck Between a Rock and a Hard place
    By kwigibo in forum C++ Programming
    Replies: 2
    Last Post: 05-14-2002, 05:57 PM