#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Help with a program


    Hello forum members!!!I need help in one program i need to complete.Let me explain u.The program ask for user to give everytime a number and this number must be Libra e.x 2,4,6,8... if its not then u add +1 to make it libra.After that the numbers the user gives correspond to * symbol and u need to print on screen this: So in every line after second u got 2 more stars. I made a very small part of the code but im very confused please if u can help me


    *
    **
    ****
    ******
    ********
    Code:
    int i; int s; for (i=0; i<7; i++)  {       printf("give number");     scanf("%d",&s);      if ( ( s/2 == 1) )     {            s = s + 1;     }                           }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    101
    Rep Power
    0
    First, you have a problem here.

    Code:
    if ( ( s/2 == 1) )
    From looking at this (I maybe wrong because you really didn't line up your coding well) s is the variable that the user sends their input to. The reason this wouldn't work is because right after 2 comes 4, then 6, then 8. 4/2 != 1. 6/2 != 1. 8/2 != 1. So that if statement would only work on the first try.

    Change it to
    [CODE]
    if (s % 2 == 0)

IMN logo majestic logo threadwatch logo seochat tools logo