Thread: another simple program help

  1. #1
    Registered User
    Join Date
    Nov 2002

    Question another simple program help

    i am trying to write a simple program in which you enter a number e.g.4 and the printout would be ****. or if u entered 10, then the output would be ten of * i.e. **********.
    i only started programming last week so not got too fa so far. any help appreciated! cheers!!

    heres what ive done so far

    #include <stdio.h>

    int x;
    char = *

    printf("enter your number\n");
    scanf("%d", &x);

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    You need to research loops. Lookup both the for and while loops. There are plenty of examples on here if you don't have your book handy.

    >>char = *
    This would be:
    >>char Output = '*';
    where Output is the variable's name.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Oct 2002
    The program will look like this:

    PHP Code:

    #include <stdio.h>

    int main()
    int x;               /* space for the user's number */
    char c '*';    /* the character to display */ 
    int i;                /* counter for the "for" loop */
    printf("Enter your number: ");
    scanf("%d", &x);
       for (
    0xi++)       /* counts how many times to print the character */
    printf("%c"c);              /* print the character */
    return 0;

    Of course if the user must enter a number, if he enters something else there will be an error: our x variable is made to hold integer numbers only.

    Studying loops is a good idea, copy-pasting this code will get you nowhere...
    Hope I helped.
    Last edited by Deltree; 11-04-2002 at 09:12 AM.
    All my brilliant admirable outstanding creations are here:
    take a look!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a very simple program
    By htdefiant in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2007, 01:27 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  4. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM