Thread: Need help with a turbo c program....urgent plz help

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    Unhappy Need help with a turbo c program....urgent plz help

    dear friends,
    i have this assignment for class which is getting on my nerves every time i try to write the program.
    the program is as follows...

    there will be a variable 'n' which must be entered by the user. For example if a value of 7 is entered for 'n', then in the display it will print a sand-clock consisting of 7 stars on the first line. 5 stars in the second line. 3 stars in the third line. and 1 star in the fourth line. after that it will increase again like before. like 3 stars on the fifth line. 5 stars in the sixth line. and again seven stars in the seventh line.


    *******
    *****
    ***
    *
    ***
    *****
    *******

    THIS.
    Please help me with this assignment.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Forum rules clearly state that help is to be provided only after the Op provides us with his attempt to solve the problem. Do your own homework, if u have questions ask.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    6
    but wat if i try n try n my deadline passes away.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Perhaps a different choice of major?

    BTW: Turbo C is >20 years old. Tell your instructor it's 2010.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > For example if a value of 7 is entered for 'n', then in the display it will print a sand-clock consisting of 7 stars on the first line.
    So can you do that - yes or no?
    Input an integer (say 7), and print that many *'s using a loop?

    > 5 stars in the second line. 3 stars in the third line. and 1 star in the fourth line
    Can you write a loop which prints 7, 5, 3, 1 ?
    If you can, can you merge that with the first loop, to print a variable number of *'s ?

    The rest is easy if you can get that far.

    Otherwise, relax knowing that future (and much harder) homework will be of no trouble to you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by hassan_shohag View Post
    but wat if i try n try n my deadline passes away.
    I told you before. Unless you post your tries here, there is no evidence that you have tried and no help is coming your way.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Registered User
    Join Date
    Jun 2010
    Posts
    6
    @ rags_to_riches :brother the thing is i m totally new at programming. so may be my instructor thought its better to take the stairs rather than taking the elevator.


    @ Salem: brother i have problems in understanding the for loop fully. And tell you what , my instructor is a SONOFA........... everytime i ask him to explain it in a clearer way, he reply me to try my self.

  8. #8
    Registered User
    Join Date
    Jun 2010
    Posts
    6
    Code:
    	printf("n:");
    	scanf("%d",&n);
    	for(i=n;i>=1;i--)
    	{
    	printf("*",i);
    	printf(" \n*",i-2);
           }
           for(i=1;i<=n;i++)
    	{
    	printf("*",i);
           }

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > printf("*",i);
    What are you expecting to happen here?
    It won't print a row of *'s.

    Simplify the code - do one step first, try it, run it, make sure you understand it.

    Trying to solve it all in one go will just confuse you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    That SOB instructor is right, though. Programming (after you learn the basic syntax and logic for the language), is about problem solving, and this is a simple problem.

    Think of it like you would do it yourself, with paper and pencil. What steps would you take, in simplest terms?

    Write it down - that's the start of your pseudo code, right there. Now start working your pseudo code, into rough code. Leave out the details, for now, whenever feasible. Get the flow, the broad strokes of logic and functions and blocks of code, worked out: input, processing, output - whatever you think is right.

    Now polish the code, and add in your details. What I'm emphasizing is that you need to organize your thoughts on the problem - get to know the problem like the "back of your hand", and THEN you'll be able to follow these steps to make your program.

    You may not like your instructor now, but you'll appreciate the results, when you work this problem, through. Every Coach has to push his athletes, to get the best out of them. Same with a good instructor.

  11. #11
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Indeed, although I think Adak is under the influence of having watched too much World Cup lately
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. im a noob at c++, do you think so?
    By belRasho in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2010, 11:02 PM
  2. Help with simple decryption program plz!
    By allen9190 in forum C++ Programming
    Replies: 3
    Last Post: 03-11-2010, 10:31 AM
  3. Debugging strings program help plz
    By allen9190 in forum C Programming
    Replies: 1
    Last Post: 11-08-2009, 08:17 PM
  4. Plz help wit my program
    By psychaospath in forum C++ Programming
    Replies: 4
    Last Post: 03-10-2006, 05:13 PM