help.... newbie! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help.... newbie!

omair19omair19 Posts: 39Member

where is the mistake in program it is not compiling!!!
thanks in advance


# include
int main (void)
int weight[3];
while (weight[1] >= 0)
{


printf ('' enter weigjt in pounds/n"");
scanf (''%d'', &weight[1]);
weight[2] = weight[1] * 4;
printf(''your weight in ounce is %d'',weight[2]);
printf (''reenter'');
scanf(''%d'',&weight[3]);
}

Comments

  • sundararamsundararam Posts: 28Member
    :
    : where is the mistake in program it is not compiling!!!
    : thanks in advance
    :
    :
    : # include
    : int main (void)
    : int weight[3];
    : while (weight[1] >= 0)
    : {
    :
    :
    : printf ('' enter weigjt in pounds/n"");
    : scanf (''%d'', &weight[1]);
    : weight[2] = weight[1] * 4;
    : printf(''your weight in ounce is %d'',weight[2]);
    : printf (''reenter'');
    : scanf(''%d'',&weight[3]);
    : }
    :
    I don't understand which part of your question is a typo and which is the real mistake in the program, but as far as I know, the following peice of code should work(though I don't understand the last few lines inside the loop achieve):
    [code]
    [size=2]
    #include
    int main (void)
    {
    int weight[3];
    weight[1] = 1; /*Some value greater than one will do*/
    while (weight[1] >= 0){
    printf ("Enter weight in pounds
    ");
    scanf ("%d", &weight[1]);
    weight[2] = weight[1] * 4;
    printf("your weight in ounce is %d",weight[2]);
    printf ("reenter");
    scanf("%d",&weight[3]);
    }
    }
    [/size]
    [/code]
    And why did you use two single quotes everywhere while a double-quotes is what is needed? Even that might be the reason of your problem(assuming you are a real newbie).
    [hr]
    [Green]Mother Nature[/Green][Purple] needs your help... Please visit: [/Purple]http://www.greenpeace.ca/e/resource/green/everyday.php
    [hr]

  • stoberstober Posts: 9,765Member ✭✭✭
    : [code]
    : #include
    : int main (void)
    : {
    : int weight[3];
    : weight[[red]0[/red]] = 1; /*Some value greater than one will do*/
    : while (weight[[red]0[/red]] >= 0){
    : printf ("Enter weight in pounds
    ");
    : scanf ("%d", &weight[[red]0[/red]);
    : weight[[red]1[/red]] = weight[[red]0[/red]] * 4;
    : printf("your weight in ounce is %d",weight[[red]1[/red]]);
    : printf ("reenter");
    : scanf("%d",&weight[[red]2[/red]]);
    : }
    : }
    : [/code]

    arrays indices always start with 0, not 1
  • sundararamsundararam Posts: 28Member
    : : [code]
    : : #include
    : : int main (void)
    : : {
    : : int weight[3];
    : : weight[[red]0[/red]] = 1; /*Some value greater than one will do*/
    : : while (weight[[red]0[/red]] >= 0){
    : : printf ("Enter weight in pounds
    ");
    : : scanf ("%d", &weight[[red]0[/red]);
    : : weight[[red]1[/red]] = weight[[red]0[/red]] * 4;
    : : printf("your weight in ounce is %d",weight[[red]1[/red]]);
    : : printf ("reenter");
    : : scanf("%d",&weight[[red]2[/red]]);
    : : }
    : : }
    : : [/code]
    :
    : arrays indices always start with 0, not 1
    :

    Ouch! That was a major mistake. Sorry friends. I ran the program, I got a correct answer, so I just posted... Carelessness is the worst enemy of C?!! :-)
    [hr]
    [Green]Mother Nature[/Green][Purple] needs your help... Please visit: [/Purple]http://www.greenpeace.ca/e/resource/green/everyday.php
    [hr]

Sign In or Register to comment.