473,320 Members | 2,052 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,320 software developers and data experts.

Simple input-output, keeps returning $0.00000

1
I wrote a simple code to calculate the total cost of gas for a week.

#include <stdio.h>

int main () {

#define MILES_PER_GALLON 23;
#define MILES_TO_SCHOOL 25;

double cost_per_gallon;
double trips;

printf("How much does gas cost this week?\n");
scanf("%lf", &cost_per_gallon);

printf("How many times does John have to drive to campus this week?\n");
scanf("%lf", &trips);
trips = trips * 2;

double miles = MILES_TO_SCHOOL * trips;
double gallons = miles / MILES_PER_GALLON
double cost = cost_per_gallon * gallons;

printf("John must spend $%lf on gas this week.\n", &cost);
}


upon compiling and running it, the final print gives "John must spend $0.00000 on gas this week."

Why?
Jan 28 '15 #1
4 993
weaknessforcats
9,208 Expert Mod 8TB
In your printf statement you specify &cost. That would be the address of cost. You want just cost.

You would use &cost in scanf to place a value in cost.
Jan 28 '15 #2
Rabbit
12,516 Expert Mod 8TB
Also missing semicolon after deceleration of gallons
Jan 28 '15 #3
weaknessforcats
9,208 Expert Mod 8TB
It turns out that the semi-colon is supplied by the macro.
Jan 28 '15 #4
donbock
2,426 Expert 2GB
Suggest you remove the semicolons from the two macro definitions. That will require you to add a semicolon to the gallons assignment.

This has the benefit of removing semicolon from middle of miles assignment.
Jan 29 '15 #5

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

Similar topics

2
by: Jason Burr | last post by:
I keep getting a server error 400 - Bad Request with the code below. xmlDoc is the MSXML.DOMDocument populated with the xml data to submit. That data is well formed and works fine if I urlencode...
1
by: Todd Peterson | last post by:
I'm a newbie to DB2 and am trying to figure out how to write a stored procedure, using dynamic SQL statements to return a result set. I believe the majority of the hurdles I have been facing might...
1
by: Frank Perry | last post by:
I have a utility that monitors whether certain third party GU applications are running and if not, it starts them up. I would lik to get rid of this utility and instead just have a Windows Service...
1
by: j090757 | last post by:
Returning parm data to vb.net from AS400 stored procedure This example loads a textbox which is used by javascript for error handling. First create the stored procedure on the AS400: CREATE...
3
by: Christian Blackburn | last post by:
Hi Gang, All I want is to be able to search a file for files matching a certain criteria. However, VB seems heart set on returning hidden folders along with my list of files. I've tried the...
3
by: giladt | last post by:
Hi, I'm a novice programmer and I've come across the following problem: I am trying to get strlen for a cosntant char array but I get back a void no matter what I try. The code looks like...
2
by: Jorgen [DK/2600] | last post by:
Hi, how do I do a simple formula, which will search a field for special characters and return a value. If it finds "%" - it returns 1 else If it finds "?" it returns 2 end
4
by: otengo | last post by:
Hi all, I tried using GetCurrentThread to get the Handle of the current thread but it keeps returning 0xfffffffe for all the threads that I access it in. This is not the correct handle. Am I...
2
by: Drew | last post by:
I am trying to build a page to generate some random data for a database that I am working on... I thought this would be simple, but it has proven to be more difficult... I am trying to create some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.