Steinhegvanhuysenolegbangbangbang (stardoll) wrote in cprogramming,
Steinhegvanhuysenolegbangbangbang
stardoll
cprogramming

First Post

So I'm a first time C Programmer, and I need all the help I can get. So please bear with me, I'm not quite clear about anything that has to do with C.

My teacher wants us to write a program that prints stars on the screen. If the number of stars is even, they should print like so:

* * * * *
* * * * *

But if it's odd, they should print like so:

* * * * * *
* * * * *

The problem I'm having is that all my stars are printing on one line, and not neatly on two. The class has to write the cute code in a for loop, and I'm having a helluva time trying to get it to work. Again, I've never programmed in C before - I've never programmed period - and I'm desperate for help.

If anyone needs to take a look at the code segment, please, let me know. I know this is not a very clear cry for help, but...I'm no good at this stuff.

Thank you.




#include <stdio.h> int main ( void ) { int number, i; char y, n, Y, N, replay; do { // LOOP NO. 1 - takes value from user and determines # of stars // do { printf ( " Enter a positive value less than 75, for number of stars: " ); scanf ( " %d", &number ); } while ( ( number < 1 ) || ( number > 75 ) ); // LOOP NO. 2 - This loop will place proper # of stars on 2 lines // for ( i = 0; i < number; i++ ) { if ( ( number % 2 ) == 0 ) printf ( " * " ); printf ( " *\n " ); } // LOOP NO. 3 - gives user option to replay star program // do { printf ( " \n " ); printf ( "Do you want to try this program again (Y-YES, N-NO): " ); scanf ( " %c", &replay ); } while ( ( replay == y || Y ) || ( replay == n || N ) ); } while ( replay == y || Y ); return ( 0 ); }


  • Post a new comment

    Error

    default userpic
  • 14 comments