Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 C program help
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cwarrior




PostPosted: Mon Mar 30, 2009 11:21 am   Post subject: C program help

Basically i have to write a program that will draw a face. like this one:

code:
   
         hhh
     hhhhhhhhh
  hhh           hhh
hhhh  O   O  hhhh
  hhh     o     hhh
   hh   \__/   hh
     h            h
     hhhhhhhhh


and i have to write the inside of the face in a function that takes 1 to draw the eyes 2 to draw the nose and 3 to draw the mouth
This is what i got:

code:

#include <stdio.h>
face(int line);
main()
{
char c = 'h';

printf("%7c%c%c \n",c,c,c);
printf("%4c%c%c%c%c%c%c%c%c \n",c,c,c,c,c,c,c,c,c);
printf("%2c%c%c%8c%c%c \n",c,c,c,c,c,c);

printf("%c%c%c%c%c%8c%c%c%c \n",c,c,c,c,face(1),c,c,c,c);
printf("%2c%c%c%8c%c%c \n",c,c,c,c,c,c);
printf("%3c%c%8c%c \n",c,c,c,c);
printf("%4c%8c \n",c,c);
printf("%4c%c%c%c%c%c%c%c%c \n",c,c,c,c,c,c,c,c,c);


}
face(int line)
{
 
  if(line == 1)
    printf(" o   o ");
  else if (line == 2)
    printf("   o   ");
  else if (line == 3)
    printf("  -   ");
}                    


I do not know how to put the function face in the main so that it displays each line properly. As you guys see I have done work I just need help with that. Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
rdrake




PostPosted: Mon Mar 30, 2009 11:37 am   Post subject: RE:C program help

There is no need to double post. If you accidentally post a topic in the incorrect forum, please PM a mod to have it moved.

Thanks.
cwarrior




PostPosted: Mon Mar 30, 2009 2:42 pm   Post subject: RE:C program help

Please only comment if you are going to help as I get notifications.
DemonWasp




PostPosted: Mon Mar 30, 2009 3:11 pm   Post subject: RE:C program help

Your code seems - to be honest - like a pretty silly way of doing this.

#1. You're using %c to fill in a single character, stored in the char variable c, which is always 'h'. Why not just use h in the first place? Much more readable.

#2. Why is face() separate from the print statements above? I'd understand if you were pulling it in from a file, but you're not - it's hardcoded right there.

If this is for an assignment, it's helpful if you post the question / assignment text so we can know if you're on the right track, or if we're leading you down the garden path.

Assuming that all you have to do is output the face in text-art, what you probably want is something like this:

code:

printf ( "         hhh" );
printf ( "     hhhhhhhhh" );
printf ( "  hhh           hhh" );
printf ( "hhhh  O   O  hhhh" );
printf ( "  hhh     o     hhh" );
printf ( "   hh   \__/   hh" );
printf ( "     h            h" );
printf ( "     hhhhhhhhh" );


Unless your assignment says otherwise, there's no reason to make it any more complex than that.
cwarrior




PostPosted: Mon Mar 30, 2009 6:53 pm   Post subject: Re: C program help

It needs to print the inside of the face using the function face; The eyes with a 1, the nose with a 2, the mouth using a 3.
so how can I do that with the function.
DemonWasp




PostPosted: Mon Mar 30, 2009 8:03 pm   Post subject: RE:C program help

Make this simple - forget about the hhhh bit and just concentrate on getting the face to output.

Try the following code in your main() method. Once you figure out how it does that, you should be able to extrapolate how to draw the rest of the face:

code:

printf("%8c\n", face(1) );
printf("%8c\n", face(2) );
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: