New to programming and need some advice

This is a discussion on New to programming and need some advice within the C Programming forums, part of the General Programming Boards category; I have to write a function that prints a character a number of times on one line and also several ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    2

    New to programming and need some advice

    I have to write a function that prints a character a number of times on one line and also several lines after. I used #define to put in 10 times and 10 lines. The following code is posted. Thanks for any help.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define TIMES 10
    #define LINES 10
    
    void showChar (void);
    
    int main(void)
    {
        
        
        showChar();
        
        
            
        system("pause");
        return 0;
        
    }
    
    void showChar (void)
    
    {
        int count = 0;
        int lineCount = 1;
                
        while (lineCount <= LINES){
                   putchar('\n');
                   
            do 
                putchar('$');
             while (count <= TIMES);
                     count++;
                     lineCount++;
         }
                    
    }

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,067
    Your outer-loop involving lineCount seems right. Consider only this outer-loop:

    Quote Originally Posted by roggoblue View Post
    Code:
        int lineCount = 1;
                
        while (lineCount <= LINES){
                   putchar('\n');
        // ... do something     
                     lineCount++;
         }
    Within the // do something part, you should write something similar for your loop involving the count variable. I would suggest putting that part in its own braces to help make it clearer

    Code:
        int lineCount = 1;
                
        while (lineCount <= LINES){
                   putchar('\n');
                    {
                        int count = ...
                        while (count ... {
                              ...
                              count++;
                        }
                    }
                    lineCount++;
         }
    Last edited by c99tutorial; 12-08-2012 at 07:39 AM.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    2
    Worked perfectly. Thanks so much. I've been beating my head over this!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to Programming: Need Help/Advice on Topic
    By AvengedGoat in forum C++ Programming
    Replies: 12
    Last Post: 08-20-2010, 11:35 PM
  2. programming assignment need advice!!!
    By jammy in forum C Programming
    Replies: 2
    Last Post: 08-06-2007, 10:16 AM
  3. Intro To Programming...need Advice Plz
    By dox82 in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2003, 12:25 PM
  4. Your advice please on what programming language to use
    By mikester in forum Windows Programming
    Replies: 2
    Last Post: 02-27-2003, 03:06 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21