Help me with my HOMEWORK!

Locked
fr0d
Posts: 584
Joined: Fri May 17, 2002 11:48 pm

Post by fr0d »


Hay guys, I have to take a stupid C course, and since I hate programming and computers in general, I am find some stuff hard. Like this questions.


 


I gotta write a program using only the following three output statements


(Each one appearing ONLY ONCE in your program):


printf("* "); printf(" "); printf("\n");


 


I am only allowed to use stuff like the if, and while stuff, and the output is supposed to be


 


* * * * * * * *


_ * * * * * * * *


* * * * * * * *


_ * * * * * * * *


* * * * * * * *


_ * * * * * * * *


* * * * * * * *


_ * * * * * * * *


 


(_ means a space, I cant get it to show)


If you help me I be best friend long time!


 


Here is the code I have so far, it doesn't work :(


 



#include <stdio.h>
int main()
{
? ? ? ?int counter1;
? ? ? ?int counter2;
? ? ? ?int counter3;
? ? ? ?counter1 = 0;
? ? ? ?counter2 = 0;
? ? ? ?counter3 = 0;
while ( counter1 != 4 ) {
? ? ? ?while ( counter2 != 8 ) {
? ? ? ?counter2 = counter2 + 1;
? ? ? ?counter3 = counter3 + 1;
? ? ? ?printf ( "* " );
? ? ? ? ? ? ? ?if ( counter3 == 8 ) {
? ? ? ? ? ? ? ? ? ? ? ?printf ( "\n" );
? ? ? ? ? ? ? ? ? ? ? ?printf ( " " );
? ? ? ? ? ? ? ?}

? ? ? ?}
counter1 = counter1 + 1;
counter3 = 0;
counter2 = 0;
}
return 0;
}



JFK
Posts: 860
Joined: Mon Dec 03, 2001 11:06 am

Post by JFK »

paging michael p jagels

Michael-Corleone
Posts: 1398
Joined: Wed Apr 03, 2002 8:11 am

Post by Michael-Corleone »

paging miguel paolo jagelo

sh3p
Posts: 771
Joined: Tue Aug 28, 2001 10:09 am

Post by sh3p »

paging moses

MikeJ
Posts: 686
Joined: Fri Oct 26, 2001 9:11 am

Post by MikeJ »


This should work dawg


 



#include <stdio.h>

int main()
{
 int iLines = 0;
 int iStars = 0;
 
 
 while ( iLines != 8 )
 {
   while ( iStars != 8 )
   {
     if ( (iLines % 2) == 1 && iStars == 0 )
     {
       printf( " " );
     }
     
     printf( "*" );
     iStars++;
   }
   iStars = 0;  
   printf( "\n" );
   iLines++;
 }
 return 0;
}



 


iLines % 2 returns 1 if odd, else returns 0 if even.


Hamburglar
Posts: 283
Joined: Wed Aug 29, 2001 11:33 pm

Post by Hamburglar »


I have no idea what's going on in this thread.


 


MikeJ is the man.


fr0d
Posts: 584
Joined: Fri May 17, 2002 11:48 pm

Post by fr0d »


This should work dawg

 



#include <stdio.h>

int main()
{
?int iLines = 0;
?int iStars = 0;
?
?
?while ( iLines != 8 )
?{
? ?while ( iStars != 8 )
? ?{
? ? ?if ( (iLines % 2) == 1 && iStars == 0 )
? ? ?{
? ? ? ?printf( " " );
? ? ?}
? ? ?
? ? ?printf( "*" );
? ? ?iStars++;
? ?}
? ?iStars = 0; ?
? ?printf( "\n" );
? ?iLines++;
?}
?return 0;
}



 


iLines % 2 returns 1 if odd, else returns 0 if even.







 


I love you in the most manly way possible. Thanks a bunch, this has been racking my mind for days


Stiffer
Posts: 478
Joined: Mon Mar 18, 2002 7:31 pm

Post by Stiffer »

:D

mr_lee
Posts: 882
Joined: Tue Aug 28, 2001 12:04 am

Post by mr_lee »


I have no idea what's going on in this thread.

 


MikeJ is the man.







 


my oath he is. that's mad! nice one mike :)


 


gj gj


 


what a helping community we are :)


Locked