Noob needs some help

This is a discussion on Noob needs some help within the C++ Programming forums, part of the General Programming Boards category; I just got back into C++ and it seems like so much has changed since i last messed with it ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    2

    Noob needs some help

    I just got back into C++ and it seems like so much has changed since i last messed with it at all, like the #include<header.h>, what happened????

    Anyway, like I said i just got back into programming a little bit, I figure its better than wasting my time watching TV, so i started doing little tutorials and then making my own stuff just so I can see if I know what im doing

    Code:
    #include<iostream>
    using namespace std;
    void whatsthatnumber(int* simple, int* simple2);
    int main(void)
    {
        int num1;
        int num2;
        int result; 
        int answer;
        
        cout << "Do you want to run the small program? Press 1 for YES, anything else for NO" << endl;
        cin >> answer;
        if (answer == 1)
        {
               answer = ;    
               whatsthatnumber(&num1, &num2);    
        }
        else
        {
          cout <<"Thanks anyway"<<endl;
          system("PAUSE");
          return 0;  
        }
        
        whatsthatnumber(&num1, &num2);  
        result = (num1 + num2); 
        cout << endl;
        cout << result;
        
        system("PAUSE");
        return 0;
    }
    // int* is to pass variables to other functions, like piPointer1, can not be used in main() unless you do int* which sets the number to your memory instead of just in the function itself
    void whatsthatnumber(int* simple, int*simple2)
    {
         cout << "input the first number: " << endl;
         cin >> *simple;
         cout <<"Input the second number: "<<endl;
         cin >> *simple2;
         cout<<"Thanks..calculating.."<<endl;
         cout<<"."<<endl;
         cout<<".."<<endl;
         cout<<"..."<<endl;
    }

    thats what I wrote...

    If I hit 1, which brings me to the whatsthatnumber() function, ill get to input the two numbers, and thats fine, but after I hit enter after the second number, it makes me input the numbers again for some reason, can anyone tell me what im doing wrong?

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    2
    Wow, nevermind, I just found out why..
    Code:
    whatsthatnumber(&num1, &num2);
    just took that out of my main funtion to call the variables again which was running the function again, not needed i guess

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    ike the #include<header.h>, what happened????
    iostream.h and family got deprecated with the C++ standard.
    http://www.google.ca/search?hl=en&q=...e+Search&meta=
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    The answer lies in your code:
    Code:
        if (answer == 1)
        {
               answer = ;    
               whatsthatnumber(&num1, &num2);    
        }
        else
        {
          cout <<"Thanks anyway"<<endl;
          system("PAUSE");
          return 0;  
        }
        
        whatsthatnumber(&num1, &num2);  
        result = (num1 + num2); 
        cout << endl;
        cout << result;
    Btw, green line is illegal and you can also use references instead of pointers, if you like. Read up on them if you don't know them. They're easier for what you're trying to accomplish.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob Q: How to read a value of a byte in binary?
    By Hitsuin in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 02:46 PM
  2. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 07:08 PM
  3. I'm a noob and I need help.
    By nifear4 in forum C Programming
    Replies: 17
    Last Post: 10-14-2008, 01:20 PM
  4. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM
  5. noob: compiling error... plz help!
    By chosii in forum C Programming
    Replies: 2
    Last Post: 05-10-2002, 05:53 AM

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