473,408 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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...



Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. // Constant
  4. #define COST_OF_GLASS .02
  5.  
  6. int main() {
  7.  
  8.     // Declare and initiate variables
  9.     int length; 
  10.     int width; 
  11.     int height;
  12.     int cost;
  13.  
  14.     // Prompt length
  15.     printf("Please enter the length of the tank.\n");
  16.     scanf("%lf", &length);
  17.  
  18.     // Prompt width
  19.     printf("Please enter the width of the tank.\n");
  20.     scanf("%lf", &width);
  21.  
  22.     // Prompt height
  23.     printf("Please enter the height of the tank.\n")
  24.     scanf("%lf", &height);
  25.  
  26.     // Calculate glass demensions
  27.     total1 = (length * height)*2
  28.     total2 = (length * width)*2
  29.     total3 = (height * width)
  30.     total = total1 + total2 + total3
  31.     cost = total * .02
  32.  
  33.     // Print results
  34.     printf("The goldfish tank costs %lf cost to build")
  35.  
  36.     return 0;
  37. }
Sep 14 '07 #1
2 1537
Savage
1,764 Expert 1GB
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
Sep 14 '07 #2
mattmao
121 100+
// 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);
Sep 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: R. Gregg Reed | last post by:
I'm trying to intergrate a cgi affiliate tracking system into a php website. When someone pays using PayPal it's supposed to direct them to one page if the payment is a success or another if...
0
by: Jacek Trzmiel | last post by:
Hi, I have a problem with using urllib2 with threading module under Cygwin. $ cygcheck -cd cygwin python Cygwin Package Information Package Version cygwin 1.5.5-1...
4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
80
by: Christopher Benson-Manica | last post by:
Of course one can get the effect with appropriate use of existing operators, but a ^^ operator would make for nice symmetry (as well as useful to me in something I'm working on). Am I the only one...
25
by: August Karlstrom | last post by:
Hi, Can someone explain the reason for the warning from GCC below: <shell-session> $ cat test.c #include <stdbool.h> bool a, b, c, d;
3
by: serge | last post by:
How do I determine which method I should use if I want to optimize the performance of a database. I took Northwind's database to run my example. My query is I want to retrieve the Employees'...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
3
by: NorthernMonkey | last post by:
Hi, I'm new here so if anything I post is not allowed please correct it for me. I've been assigned a task of displaying a variable of unsigned int as a binary number in C++. I can do this fine...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.