|
-
October 18th, 2010, 12:27 PM
#16
Re: Printing patterns
 Originally Posted by ttrz
Code:
printf("%c %c\n", '*', '*');
While this will work, substituting literals is really not necessary here:
will do the same thing.
 Originally Posted by adam86107
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.
-
October 19th, 2010, 10:34 AM
#17
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.
-
October 19th, 2010, 11:39 AM
#18
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;
}
-
October 19th, 2010, 05:56 PM
#19
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|