Thread: Newbie C Programer Needs Help ASAP

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    52

    Newbie C Programer Needs Help ASAP

    Well I am curentley taking a C class at my school and am working on a code right now and I am having quite a bit of Trouble. I know most of you have more experance than I therefore I will post what is needed and what I have thus far...I am having troubles with the for loop is there anyway instead of printing out 4
    3
    2
    etc I could get it to throw out the correct amount of * for the number it is inplace of ?

    This is what I have so far

    /* Written by:
    UT
    Assignment Number Four
    Feb. 21, 2002
    */

    #include <stdio.h>
    #include <conio.h>

    void main (void)
    {
    int a,z;
    do{
    printf("Please enter an odd number greater than five...");
    scanf("%d", &a);
    z=a%2;
    }
    while (a<5||z<1);

    for(z=a ; z > 0; z=z-1)
    {
    printf("%d\n",z);
    }




    getch();
    }

    This is what the Assigment requires.

    Use a combination of different structures you have learned to far (sequences, conditions, jumps and loops) to create an output to form:

    **********
    *******
    *****
    ***
    *

    You should ask the user to enter an odd number.
    Check and discard even, and negative numbers
    Odd numbers less than 5 should also be discarded.
    Each row has two stars less than the one above

    Okay as you can see I am pretty lost any help is appraicted thanks in advance guys
    Last edited by Halo; 02-20-2002 at 11:31 PM.

  2. #2
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    Try something like.....

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
         int x,y;
    
    
         printf("\n\tInput Number (Greater than 5, Not Even): ");
         scanf("%i",&x);
    
         if ((x<5) || (x%2=0))
         {
             printf("\n\tInvalid Entry!");
             return 0;    // Quits the Program //
         }
    }
    that's all i'm giving you...it's pretty muh what you had....structured bit better......all you need to do now...is to add a loop after that whole if statement....firs you want the loop to be executed the same amount of times as x, and the only thing in the loop should be a printf("*"); so the loop will just print an x amount of astrieks..then after that....every other line will have a (x-2) amount of stars........you should be able to figure it out now ...try it.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    you probably want something like this:

    int num //I'll leave getting this value to you.

    for(num; num >= 0; num--)
    {

    numcopy = num;

    for(numcopy; numcopy >= 0; numcopy--)
    {
    printf("*");
    }

    printf("\n");
    }

    that should give you the results you're looking for.

    -starX
    www.axisoftime.com

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    I am not familair with num copy can someone tell me what this function does ? Sounds like it could be useful in the future if it does what I think it does :-)

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    Hi,
    the numcopy that star x has shown as an example is not a actual function but is an integer varaible used as example to yourself as a counter...he could have easy have taken the option of using the more preferred counter variable names of count, i or j.
    Code:
    int num; /* for user input */
    int i, j; /* counters  */
    /* rest of your code ..then */
    for(i = num; i >= 0; i--) 
    { 
    
    j= i; 
    
    for(j; j>= 0; j--) 
    { 
    printf("*"); 
    } 
    
    printf("\n"); 
    }
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  2. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 06:46 AM
  3. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM