assignment help. [urgent]

This is a discussion on assignment help. [urgent] within the C Programming forums, part of the General Programming Boards category; i am having huge problems continuing with an assignment due in four days. Code: #include <stdio.h> void main() { int ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    Ireland
    Posts
    19

    assignment help. [urgent]

    i am having huge problems continuing with an assignment due in four days.
    Code:
    #include <stdio.h>
    
    void main()
    {
    	int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;
    	
    	printf("enter max factorial\n");
    	scanf("%d", &i);
    	printf("enter min factorial\n");
    	scanf("%d", &minfactorial);	
    	printf("--------------------------------------------------------------------");
    	while (line<=0){
    	printf("\nFactorial Value        Factorial expression            Result");
    	line=line+1;
    	}
    	maxfactorial=i;
    	factorial=i;
    	while ( factorial>=minfactorial){
    	printf("\n%d" ,maxfactorial);
    	maxfactorial=maxfactorial-1;
    	factorial=factorial-1;
    	}
    
    
    }
    the assignment is attached and the code above is what i have got so far. any suggestions or help no matter how small would be appreciated.
    Attached Files Attached Files

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409

    Problem?

    Considering this is urgent you have not really filled us in on the details, like what is the problem you are having? I cant be bothered going through an assignment question, just say what the issue is with code you posted

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Ciaran789 View Post
    i am having huge problems continuing with an assignment due in four days.
    Code:
    #include <stdio.h>
    
    void main()
    {
    	int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;
    	
    	printf("enter max factorial\n");
    	scanf("%d", &i);
    	printf("enter min factorial\n");
    	scanf("%d", &minfactorial);	
    	printf("--------------------------------------------------------------------");
    	while (line<=0){
    	printf("\nFactorial Value        Factorial expression            Result");
    	line=line+1;
    	}
    	maxfactorial=i;
    	factorial=i;
    	while ( factorial>=minfactorial){
    	printf("\n%d" ,maxfactorial);
    	maxfactorial=maxfactorial-1;
    	factorial=factorial-1;
    	}
    
    
    }
    the assignment is attached and the code above is what i have got so far. any suggestions or help no matter how small would be appreciated.
    To print the factorial value, just make another function which returns the factorial of maxnumber. I'm modifying your code, I dont know if it's efficient or not.
    Code:
    #include <stdio.h>
    int fact(int num)
    {
    	int i,facto=1;
    	for(i=1;i<=num;i++)
    		facto=facto*i;
    	return facto;
    }int main(void)
    {
    	int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;
    	
    	printf("enter max factorial\n");
    	scanf("%d", &i);
    	printf("enter min factorial\n");
    	scanf("%d", &minfactorial);	
    	printf("--------------------------------------------------------------------");
    	while (line<=0){
    	printf("\nFactorial Value        Factorial expression            Result");
    	line=line+1;
    	}
    	maxfactorial=i;
    	factorial=i;
    	while ( factorial>=minfactorial){
    	printf("\n%d%60d" ,maxfactorial,fact(maxfactorial));
    	maxfactorial=maxfactorial-1;
    	factorial=factorial-1;
    	}
    return 0;
    }
    Always remember main returns int not void.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Don't give out solutions!
    Newbies learn nothing if you do it.
    It is they who must learn, not us. We get nothing by simply handing out solutions except create more dumb programmers out there who do not deserve their title.
    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.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Location
    Ireland
    Posts
    19
    thanks, i understand that bit now. one more question. do i need to use a loop to print the factorial expression?

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    14
    Well, yes. The loop should go from the number (x from x!) down to 1.

    But I don't get why you did this:
    Code:
    int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;
    
    ...
    
    
    while (line<=0){
    	printf("\nFactorial Value        Factorial expression            Result");
    	line=line+1;
    }
    You don't need a loop if you want to do something only once.
    Last edited by Junky; 11-29-2009 at 07:50 AM.

  7. #7
    Registered User
    Join Date
    Nov 2009
    Location
    Ireland
    Posts
    19
    i put the while loop in because it was the only way i could get it to work. im not that good at programming yet.only in my first year.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Start by making a flowchart.
    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.

  9. #9
    Registered User
    Join Date
    Nov 2009
    Posts
    14
    Quote Originally Posted by Ciaran789 View Post
    i put the while loop in because it was the only way i could get it to work. im not that good at programming yet.only in my first year.
    It will work fine without the loop, you just did something else wrong.

  10. #10
    Registered User
    Join Date
    Nov 2009
    Location
    Ireland
    Posts
    19
    thanks for the help guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 08:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM

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