Thread: Functions help

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    82

    Functions help

    i wanted to see if i could get a simple function setup, something called from within in main nothing to hard...

    Well it worked eventually, at least i think it did and the funciton was called. So i wanted to see if i could add another, however after adding it, it compiled but nothing happens. The original function isn't called anymore, even though i would have thought by looking at it that it would call the first one (sequence),a dnt hen the next one (alldone) after input into the first function is done.

    any ideas on what simple fundemental thing i've done wrong
    it's not like i've spent several hours on it already

    Code:
    # include <iostream>
    # include <stdio.h>
    
    using namespace std;
    
    int Seqeunce(void)
    
    {
          
          int Sequence ;
          
        cout << "Input Residue Sequence: "<< endl;
        cin >> Sequence;
        cin.ignore();
        
         cout << "Sequence entered: "<< Sequence <<"\n";
         
         
       return 0;
      
    }
    int Alldone(void)
    
    {
        char done;
        
        cout <<"All Done!"<< endl;
        cin >> done;
        cout << "Done: "<< done <<"\n";
        return 0;
    }
    
    
    
    int main (int argc, char* argv[]) 
    {
    
    
    {
        Seqeunce();
    }
    
    {    
        Alldone();    
    }    
    
    
    cin.get();
     }

  2. #2
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    You dont use these "{" in main, just:
    Code:
    int main(){
     //all code here
    }
    edit: I have tested your code and it works here.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The extra parentheses shouldn't cause any problems. The code work for me. What input do you give?

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    Alldone() is called, you just have to enter a number or a letter.
    Input Residue Sequence:
    3
    Sequence entered: 3
    All Done!
    2
    Done: 2
    Press any key to continue
    your main() function should "return 0" or you will get warning.

    you will get the same result if you make your function return void and removing the return 0; in both of them.
    When no one helps you out. Call google();

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Why do you add the extra
    Code:
    { }
    groups in main? As for your problem the program compiled and ran fine for me. I did have problems when entering a non-integer in the first input though, perhaps this is your case?

    Oh, and you should include <cstdio> instead of <stdio.h>
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    Thank you all, i don't even thin i want to mention the embaressment when i found out it wasn't running because even though i clcked compile and run in dev c++ it decided to run a seperete exe file.

    I'am now going to scratch my eyes out while i contemplate how i got myself into this situation

    apologises for all who got it to work first time. i didn't mean to waste your time sorry.

    regards Wolfe

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> your main() function should "return 0" or you will get warning.

    Only on older, non-standard compilers. You are allowed to leave out the return 0 in the main function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM