1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem running code after compiling

Discussion in 'C' started by Rocky48, Jun 11, 2016.

  1. Rocky48

    Rocky48 New Member

    Joined:
    Jun 11, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Retired
    Location:
    Hastings, UK
    Hi! I'm new to C programming and I can't understand what is happening.
    I have written some code to calculate the number of rolls of wallpaper to decorate a room.
    I have compiled it and at first it worked OK, using it in my C compiler program (LCC Wedit).
    Subsequently I tried running it by clicking on the executable and it does not run and returns code -1 instead of 0. Even if I return to the compiler program it comes up with the same return code.
    Why is this happening?
    Here is the code:
    Code:
    #include <stdio.h>
    #include <conio.h>
    int main(void) {
    float ht, wall1, wall2, wall3, wall4, winht, winwidth, wallarea,Wpaperwid,Wpaperarea, NoLen, NoRolls;
    printf("Height of wall to be wallpapered = ? ");
    scanf("%f", &ht);
    printf("Width of Wall 1 = ? ");
    scanf("%f", &wall1);
    printf("Width of Wall 2 = ? ");
    scanf("%f", &wall2);
    printf("Width of Wall 3 = ? ");
    scanf("%f", &wall3);
    printf("Width of Wall 4 = ? ");
    scanf("%f", &wall4);
    printf("Width of Window = ? ");
    scanf("%f", &winwidth);
    printf("Height of Window = ? ");
    scanf("%f", &winht);
    wallarea = ((ht*wall1)+(ht*wall2)+(ht*wall3)+(ht*wall4)-(winht*winwidth));
    printf("Total area of Walls, less Window = ");
    printf("%f\n", wallarea);
    printf("Width of Wallpaper = ?");
    scanf("%f", &Wpaperwid);
    Wpaperarea =(ht*Wpaperwid);
    printf("Area of one length of Wallpaper = ");
    printf("%f\n", Wpaperarea);
    printf("Number of lengths of Wallpaper = ");
    NoLen=(wallarea/Wpaperarea);
    printf("%f\n", NoLen);
    NoRolls=(ht*NoLen/10);
    printf("Number of Rolls of Wallpaper= ");
    printf("%f\n", NoRolls);
    return(0);
    }
    
     
  2. Rocky48

    Rocky48 New Member

    Joined:
    Jun 11, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Retired
    Location:
    Hastings, UK
    Woo!
    Whats going on?
    Found a way of running program called Execute on the Utils menu and it ran and and let me input the values, but When I got to the last input and pressed enter the console closed, so I could not se the result. I think it may have written the result to the screen, but closed immediately. How do you hold the console open until you hit a key, like it did in the compiler program?
     
  3. Rocky48

    Rocky48 New Member

    Joined:
    Jun 11, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Retired
    Location:
    Hastings, UK
    Figured a work around!
    wrote a batch file and put a pause in after the exe had run.
     

Share This Page