Thread: Need help with C homework problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    6

    Need help with C homework problem

    Hello,


    My name is ali and I am currently enrolled in edx.org program for computer science. On my problem set I was assign to create the pillars in mario:


    jharvard@appliance (~/Dropbox/pset1): ./mario
    Height: 8
    ##
    ###
    ####
    #####
    ######
    #######
    ########
    #########

    ****The pillars are aligned to the left and not right but for some reason it won't let me post it that way.****


    I have to first prompt the user for the half-pyramid's height, a non-negative integer no greater than 23. (The height of the half-pyramid pictured above happens to be 8.) If the user fails to provide a non-negative integer no greater than 23, you should re-prompt for the same again. Then, generate (with the help of printf and one or more loops) the desired half-pyramid. Also I have take care to align the bottom-left corner of your half-pyramid with the left-hand edge of your terminal window.


    So far this is what I got from my solution. But the problem is They don't align properly and I don't understand how to use the \n in a loop to make that happen:


    Code:
    #include <stdio.h>
     
    int main(void)
    {
        int h, s, i;
            
            do
            {
                printf("Height: ");
                scanf("%d", &h);
            }
            while(h <= 0 || h > 23);
            
            for(s = 0; s < h - 1; s++)
            {
                printf(" ");
            }    
            for(i = 0;i < h ; i++)
            {   
                printf("#");
            }    
            
            
            return 0;
        
    }

    I can only use "do" "while" and "for" to solve this problem. I would really appreciate it if someone could guide me here
    Last edited by Salem; 11-23-2012 at 11:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework problem!
    By arsenalftw067 in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2012, 01:07 AM
  2. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  3. Need help please with a homework problem
    By AxlRose in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2004, 01:25 PM
  4. homework problem
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 08-09-2002, 07:12 PM
  5. Help Me with this homework problem Please!!
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2002, 07:54 PM