Logical errors in code, output not correct

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeffcbr
    New Member
    • Sep 2007
    • 1

    #1

    Logical errors in code, output not correct

    I am very new to programming and do not know what is wrong with this code...
    project due soon. need feedback asap please...



    [CODE=c]#include <stdio.h>

    // Constant
    #define COST_OF_GLASS .02

    int main() {

    // Declare and initiate variables
    int length;
    int width;
    int height;
    int cost;

    // Prompt length
    printf("Please enter the length of the tank.\n");
    scanf("%lf", &length);

    // Prompt width
    printf("Please enter the width of the tank.\n");
    scanf("%lf", &width);

    // Prompt height
    printf("Please enter the height of the tank.\n")
    scanf("%lf", &height);

    // Calculate glass demensions
    total1 = (length * height)*2
    total2 = (length * width)*2
    total3 = (height * width)
    total = total1 + total2 + total3
    cost = total * .02

    // Print results
    printf("The goldfish tank costs %lf cost to build")

    return 0;
    }[/CODE]
    Last edited by Ganon11; Sep 15 '07, 07:53 PM. Reason: Please use the [CODE] tags provided.
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Originally posted by jeffcbr
    I am very new to programming and do not know what is wrong with this code...
    project due soon. need feedback asap please...



    #include <stdio.h>

    // Constant
    #define COST_OF_GLASS .02

    int main() {

    // Declare and initiate variables
    int length;
    int width;
    int height;
    int cost;

    // Prompt length
    printf("Please enter the length of the tank.\n");
    scanf("%lf", &length);

    // Prompt width
    printf("Please enter the width of the tank.\n");
    scanf("%lf", &width);

    // Prompt height
    printf("Please enter the height of the tank.\n")
    scanf("%lf", &height);

    // Calculate glass demensions
    total1 = (length * height)*2
    total2 = (length * width)*2
    total3 = (height * width)
    total = total1 + total2 + total3
    cost = total * .02

    // Print results
    printf("The goldfish tank costs %lf cost to build")

    return 0;
    }
    For inputing integer, flag is %d,not %lf.

    Savage

    Comment

    • mattmao
      New Member
      • Aug 2007
      • 121

      #3
      // Print results
      printf("The goldfish tank costs %lf cost to build")

      should be:

      // Print results
      printf("The goldfish tank costs %lf cost to build", cost);

      Comment

      Working...