newbie needs help with C++ program

This is a discussion on newbie needs help with C++ program within the C++ Programming forums, part of the General Programming Boards category; I am a newbie taking introductory to C++ this is my first programming class taken. I am having trouble with ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    4

    Question newbie needs help with C++ program

    I am a newbie taking introductory to C++ this is my first programming class taken. I am having trouble with a homework assignment. I am not asking anybody to do my work for me just point out my mistakes since i can't seem to get help from my professor.

    I am writing a code for binomial numbers. whenever i try to compile the code in visual C++ 6.0 i get 4 errors and i cant run debug because the program isn't built yet. So can somebody please tell me how i can get visual C++ 6.0 to show me where the errors are.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    After you try to compile your code, press Alt-2 or go to the View menu and select the Output option (Alt-V then O). This will bring up the Output window where the error messages are displayed.
    "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

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Post the erros and the corresponding code.

    Kuphryn

  4. #4
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    I'm just going to guess what your problems are-
    you forgot a ; some where.
    you forgot to declare a variable you are using in a for loop
    you didn't prototype your function - so it says it's undefined
    and last but not least you don't have a propper stop condition on your conversion recursion function.


    Lemme know how close I am.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Or the last 3 errors were spawned because of the first one.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    4
    O.k i see the errors but i don't think that it is right unless i am doing something really wrong.

    The errors are

    binomial.cpp(61) : error C2143: syntax error : missing ';' before '<'

    binomial.cpp(61) : error C2143: syntax error : missing ';' before '<'

    binomial.cpp(64) : error C2143: syntax error : missing ';' before '{'

    binomial.cpp(64) : error C2447: missing function header (old-style formal list?)

    If i am reading this right the errors should be on 61 and 64

    and this is what is on those lines

    Code:
    /*    binomial coefficient nCk (integer) */<![endif]>
    
    
    {
    so don't think these could be the errors it could be something i left out in the for loop like dbgt said or i could have made an error somewhere else in the code like X said that caused these errors to pop up.

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    4
    Here is the complete code can u mark an X by the areas i got wrong. Please don't give me the answer i need to figure it so i know what i am doing. you can provide hints......

    Code:
    #include <iostream>
    
    using namespace std;
    
    int binomial (int n, int k) ; // function prototype
    
    
    
    int main()
    {
    	int n,k; // parameters for the binomial number
    	int result;
    
    	cout << endl;
    
    	// read in n & k
    
    	cout<< "Enter n (positive integer) : " ;
    	cin>> n ;
    
    	cout<< "Enter k (positive integer) : " ;
    	cin>> k ;
    
    	result = binomial (n, k) ;
    
    	cout<< "Binomial number " << n << "C" << k
    		<< " = " << result << endl ;
    
    	return (0) ;
    }
    
    //**************************************************
    
    binomial (int n, int k)
    
    /* compute the binomial coefficient nCk  */
    /*                                       */
    /* Inputs:                               */
    /*    n, k (integers)                    */
    /*                                       */
    /* Output:                               */
    /*    binomial coefficient nCk (integer) */<![endif]>
    
    
    {
    	int numerator, denominator ;
    	int i ; // needed to compute numerator & denominator <![endif]>
    
    	if (n < k)
    	{
    		return (0)
    	}
    	else
    	{
    		denominator = 1*2*...*k; // initial value <![endif]>
    
    		for (i = 1; i <= k; i++)
    			denominator = denominator  * 1 ; <![endif]>
    
    			
    	    numerator = (n - k + 1) * (n - k + 2)*...*(n - 1)<![endif]>
    
    		return (numerator / denominator);
    	} // else
    }

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    /* binomial coefficient nCk (integer) */<![endif]>
    How did an IE conditional tag ever find its way into C++ code? Remove the <![endif]> and you should be fine.

    Well, not quite. The binominal function also needs a return type.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Jun 2004
    Posts
    4

    Thumbs up

    Aight thanks corned bee

    i was only doing what my professor said he pointed his mistake out. I got it working now.


    thanks

  10. #10
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,803
    you might want to check into another classs :P
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. newbie looking for hints on first audio program...
    By BrownB in forum Game Programming
    Replies: 2
    Last Post: 07-13-2005, 07:25 AM
  3. Newbie program - improvements?
    By -JM in forum C++ Programming
    Replies: 9
    Last Post: 06-26-2005, 06:53 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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