Thread: Help a n00b out...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    44

    Help a n00b out...

    Uh. Hi. I'm new to this board, and very new to C++. Some concepts are hard for me to understand... Right now I'm learning about loops... like, for, if, else, so and so. I have to complete a few excersices for "homework" If you will. I need to create the following using the For loop. I really need help on 2-4... I figured 1 out easily. Thanks in advance.

    1)
    *****
    ****
    ***
    **
    *
    Code:
    //code I used for above
    #include<stdio.h>
    #include<conio.h>
    
    void main()
    {
    
    int i, j;
    for(i=5; i>=1; i--)
    
    {
    
            for(j=1; j<=i; j++)
            {
            printf(" * ",j);
    
            }
            printf("\n");
    
    
    }
    
    getch();
    
    }
    //Really simple...
    Now the following is what I need help with.

    2)
    ****
    --***
    ---**
    ----*

    3)
    -*
    -***
    ****

    4)
    1
    101
    1010
    10101


    Of course, I don't want you to do any of the work for me... but maybe an example or two with a different scenario, or just maybe some tips will help me on my way. I don't know much in C, so please try to stick to the most basic functions, like printf, scanf, and loops, like if, else and for. I know I could just do printf and get the same output... but that's not the point of the exercise. Again, Thanks in Advance! Oh, and teh dashes, they stand for SPACE...

    -ddy02
    Last edited by diddy02; 07-15-2002 at 09:00 PM.

  2. #2
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    post in the cforums if u want replies, i have no clue what your talking about, c++ programers hang aroudn here, not c,
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  3. #3
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    Maybe if you look at your first problem from a slightly different approach it might help you to understand the last few problems better.

    Code:
     
    #include<stdio.h>
    int main()
    {
    	for(int i = 0; i < 5; i++)
    	{
    	    for(int j = i; j < 5; j++)
    	    {
    	        putchar('*'); 
    	    }
    	    printf("\n");
    	}
    	getchar();
    	return 0; 
    }
    Your doing good so just keep working at it and you'll get it. These are always good teaching exercises so I would really like to see you get this on your own. Welcome to the boards.

    P.S Just for future reference, this thread really should have gone on the C board, not the C++ board.

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    44
    Thank you (still haven't figured it out, but getting there), and I'm sorry for not posting in the C section... I just read up on the differences and I do apologize.

  5. #5
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Don't Apologise, some people are weird.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    diddy02:

    Dont worry about posting that question here, sure you posted example C code, but if there are any C++ programmers out there that don't know what your code does then they can't call themselves programmers at all!

    In future, I wouldn't bother listening to Klinerr1. He/she doesn't have a clue what ANYONE is talking about, it's not just you.

    Here are a few pointers to help you on your way.

    For the first two example outputs you are always outputting a constant amount of characters per line. So for each row (item in your loop) you will always be outputting the same amount of chars. Looking at number 2) you are outputting 4 chars per line:

    1st line - 0 spaces, 4 *'s
    2nd line - 1 space, 3 *'s
    3rd line - 2 spaces, 2 *'s
    4th line - 3 spaces, 1 *

    see the pattern?

    for each row:
    1) output the number of spaces
    2) output the number of *'s

    to figure out how many spaces you need to print and how many *'s is quite simple. All you need is a counter of the number of spaces, starting at zero. For each time you loop, you output that number of spaces, then output 4 - numOfSpaces of * characters. make sense??

    here's some example code:

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int numSpaces = 0;
    
        for(int i = 0; i < 4; i++)
        {
            for(int j = 0; j < numSpaces; j++)
            {
                printf(" ");
            }
            for(j = 0; j < 4 - numSpaces; j++)
            {
                printf("*");
            }
            numSpaces++;
    
            printf("\n");
        }
        return(0);
    }
    now, this code does it for 4 lines, and you may want it to produce many more lines... so all you have to do is store the number in another variable like so:

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        const int numLines = 10;
        int numSpaces = 0;
    
        for(int i = 0; i < numLines; i++)
        {
            for(int j = 0; j < numSpaces; j++)
            {
                printf(" ");
            }
            for(j = 0; j < numLines - numSpaces; j++)
            {
                printf("*");
            }
            numSpaces++;
    
            printf("\n");
        }
        return(0);
    }
    does that make sense?? you can use almost the same code to solve 3), but i will leave that to you to play with.

    Question 4), you can use similar code to what you have already written.... but for this problem there are a bzillion ways of solving it

    good luck!
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  7. #7
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605

    Uraldor!!!

    You know what, Uraldor? You shouldnt flame people for making a simple suggestion. Klinner1 DOES know what he's doing, and sure you need to know C to know C++, but know what? The C++ board is to be strictly used for *C++* help, not just C. So flame Klinner1 again, and see what happens to you.

    Also, thats not a theat..THATS A PROMISE!!!



    Love,
    Civix :P

  8. #8
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    wel put it htis way.. you DO NOT HAVE TO KNOW C TO KNOW C++ some peopel even recomemend not lernign c if u plan to learn c++ and mainly use c++ because c++ is the same and has more abilties. c++ is not any harder to learn than c, samething vice versa. i know lots of people that know c++ and not c. thats why you should post c stuff ont he c forums and c++ stuff on c++ forums. like you would talk about windows programming here? or html or anything. no c++ related.

    that part that was confusing was...

    1)
    *****
    ****
    ***
    **
    *

    Now the following is what I need help with.

    2)
    ****
    --***
    ---**
    ----*

    3)
    -*
    -***
    ****

    4)
    1
    101
    1010
    10101

    i was asuming it had to do with some c ****, but than i saw some binary ****... he shoudl post stuff in c forums if he really wants answers anways.. end story
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  9. #9
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    i was asuming it had to do with some c ****, but than i saw some binary ****
    The guy is just trying to print the patterns with those characters, it really has nothing to do with C specifically and definitely nothing to do with binary code. Did you read his post at all?

  10. #10
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176

    C vs. C++

    Please excuse my ignorance, I'm learning to program C/C++ myself.

    My current understanding of C vs C++ is that:
    The difference is largely that C++ implements classes (souped up structures). Classes give rise to object oriented programming which, even though I haven't gotten too far into it, seems pretty damn handy. Some of the functions are renamed (such as new and malloc, delete and free), but I don't believe that there is any further difference. Or maybe there is...?

    Am I close, or am I lost?

    Also, if C++ is an 'improved' version of C, why bother learning C? Especially since a C program would work with a C++ compilier (I think).


    As I said, I'm learning C/C++ myself. This forum looks to be useful (there seem to be smart people here!) and I'm glad I came across it. I look forward to learning a thing or two and hopefully I'll be able to toss a few useful contributions back your way some day.

    fletch
    "Logic is the art of going wrong with confidence."
    Morris Kline

  11. #11
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176

    Open mouth, insert foot

    As soon as I submitted my post above, I find a thread in the C programming forum discussing C vs. C++. So that answers my first question.

    My second question still stands however. Why bother to learn C if you can just learn C++?


    I can definitely see how the whole C vs. C++ conversation can get really old.

    fletch
    Last edited by fletch; 07-16-2002 at 08:48 PM.
    "Logic is the art of going wrong with confidence."
    Morris Kline

  12. #12
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    Why bother to learn C if you can just learn C++?
    Personally, the best anwser I can give to that question is this. It's widely used, and in this industry the more you know the better. I am sure you can find a thread on this as well with a search. Welcome to the boards.

  13. #13
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    >>So flame Klinner1 again, and see what happens to you.

    Also, thats not a theat..THATS A PROMISE!!! <<

    Hey, whats happening to this nice little board..


    civix scares me
    and so does Klinner1's typos
    -

  14. #14
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    So flame Klinner1 again, and see what happens to you.
    Also, thats not a theat..THATS A PROMISE!!!
    Uhh....ohhh. Civix is gonna get you! He's gonna eat your children! Or maybe he will hack your computer and make your life a living hell, cuz he is a super l33t hax0r! And if he is not, I'll bet he has some FRIENDS, who are, like, total computer geniuses! You're in trouble now! Civix is one man you don't want to make mad. He's a mix between Darth Vader, Mike Tyson, and Sunlight! And you know he's not gonna break his PROMISE! Cuz anonymous people on the net ALWAYS do what they say they will.

    My God, civix, you're such a pathetic, boastful little worm
    I go to encounter for the millionth time the reality of experience and to forge in the smithy of my soul the uncreated conscience of my race.

    Windows XP consists of 32 bit extensions and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company, that can't stand 1 bit of competition.

  15. #15
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605

    Talking Haha...

    Yeh, im a worm, so boastful, has friends who are hackers, yep, gonna make life a living hell, yep, yep, yep...hey, listen, im not a hacker, and nor do i know anyone who is such a thing...Klinerr1 is my friend and programming partner, and the way I see it, i really could care less if youre gonna flame me...but Klinerr1 takes it personally. All that i was saying (yes youre stupid) is that uraldor had no right to flame Klinerr1 for such a dumb reason, and that we could all just have a little flamefest if he wanted, and look what has happened, my post turned into 3 flames toward me. Really, now, do you think im really a hacker, you sound just like the people at school...*ATTEMPTING* to make fun of people, just to make yourselves look better...(Darth Vader was weak, and Mike Tyson is just stupid.) I dont boast nothing, and im even new to the whole programming concept... People like you are just stupid...(that or Athiest) Yeah, and i know youll turn around and flame me again...but it's no use cause im not gonna care...Flame me until I catch on fire, and burn in hell... I care... why?? I'm only here to learn how to program, and to introduce my applications into circulation and get feedback..Im not here just to take crap from you guys, and you arent here just to give me crap! Now, how about we all hold hands and the board will be oh so peaceful...then we will all be happy...

    Love, Civix
    .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. n00b questions
    By C+noob in forum C++ Programming
    Replies: 43
    Last Post: 07-09-2005, 03:38 PM
  2. n00b problems
    By piebob in forum C++ Programming
    Replies: 2
    Last Post: 06-17-2005, 01:51 AM
  3. n00b Code Error.
    By Zeusbwr in forum C++ Programming
    Replies: 4
    Last Post: 10-11-2004, 05:15 PM
  4. n00b doing a Socket operation on non-socket
    By Kinasz in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-25-2004, 03:29 AM
  5. ISO someone daring to look at some n00b code!
    By Rev. Jack Ed in forum Game Programming
    Replies: 4
    Last Post: 10-17-2003, 08:45 AM