CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Printing patterns

    Quote Originally Posted by ttrz View Post
    Code:
    printf("%c         %c\n", '*', '*');
    While this will work, substituting literals is really not necessary here:
    Code:
    printf("*         *\n");
    will do the same thing.

    Quote Originally Posted by adam86107 View Post
    The instructor referred to it as a C++ class anyway.
    Well, to be blunt, there are a lot of instructors who claim to be teaching C++, who are actually teaching "C with a few bits of C++ syntax thrown in". That isn't the way professional programmers write C++, but it is unfortunately very common in schools. The reason for this is that C makes it easier to teach the underlying data structures and algorithms than proper C++, because proper C++ does a lot of the low-level stuff for you. It's important to learn those low-level ideas, but you should also become familiar with the "right" way of doing things, because it's both easier and safer.
    Last edited by Lindley; October 18th, 2010 at 12:29 PM.

  2. #17
    Join Date
    Sep 2010
    Posts
    22

    Re: Printing patterns

    OK, so here is what I've tried to do and apparently I am way off base. Everything I've tried keeps getting implicit declarations of the functions in main, but without modifying main I cant seem to figure out how to get rid of this. Here is my latest failure:

    int main (void) {
    print_1_9();
    print_2_7();
    print_3_5();
    print_4_3();
    print_5_1();
    print_6_0();
    print_5_1();
    print_4_3();
    print_3_5();
    print_2_7();
    print_1_9();
    return 0;
    }
    int myfunction (void) {
    print_1_9;
    printf("* *\n");
    print_2_7();
    printf("** **\n");
    print_3_5;
    printf("*** ***\n");
    print_4_3;
    printf("**** ****\n");
    print_5_1;
    printf("***** *****\n");
    print_6_0;
    printf("************\n");
    return 0;
    }

    Any extra help is much appreciated as this program is due today.

  3. #18
    Join Date
    Sep 2010
    Posts
    22

    Re: Printing patterns

    I've changed it up some but still to no avail. Here's the newest:

    int main (void) {
    print_1_9();
    print_2_7();
    print_3_5();
    print_4_3();
    print_5_1();
    print_6_0();
    print_5_1();
    print_4_3();
    print_3_5();
    print_2_7();
    print_1_9();
    return 0;
    }
    int myfunction (void) {
    int print_1_9();
    printf("* *\n");
    return 0;
    }
    int myfunction1 (void) {
    int print_2_7();
    printf("** **\n");
    return 0;
    }
    int myfunction2 (void) {
    int print_3_5();
    printf("*** ***\n");
    return 0;
    }
    int myfunction3 (void) {
    int print_4_3();
    printf("**** ****\n");
    return 0;
    }
    int myfunction4 (void) {
    int print_5_1();
    printf("***** *****\n");
    return 0;
    }
    int myfunction5 (void) {
    int print_6_0();
    printf("************\n");
    return 0;
    }

  4. #19
    Join Date
    Sep 2010
    Posts
    66

    Re: Printing patterns

    Name your functions print_1_9, print_2_7, print_3_5, print_4_3, etc. Don't name them myFunction - that is just something I used when giving you an example.

    To keep it simple, implement the functions first, before main. See if this helps you.

    Code:
    #include <iostream>
    
    void print_1_9() {
    printf("*         *\n");
    }
    
    int main (void) {
    print_1_9();
    return 0;
    }
    If you can't figure out how to make it work from this example, I think you are in trouble and should read the first few chapters of your C or C++ programming book again.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured