Solved

Simple C assignment

Posted on 2012-03-13
3
326 Views
Last Modified: 2012-03-13
I'm working on a simple assignment, in C. I'm having trouble getting the variables to be calculated. My output just repeats a small number and doesn't get anywhere near the value I need. This is my code that I'm utilizing:

#include <stdio.h>
#include <math.h>
#include <iostream>

int main () {

      double current, resistance, watts, voltage, miles, power_loss, total_resistance;
      
      watts = 5000000000000000000;
      voltage = 100;
      resistance = 0.05;
      miles = 20;
      current = 0;
      power_loss = 0;

      printf("Distance      Power Loss\n");

      for(miles = 20; miles <= 100; miles += 10)
      {
            total_resistance = resistance * miles;
            current = watts / voltage;
            power_loss = (current * current) / total_resistance;
            
            printf("%g      %g\n", &miles, &power_loss);
      }

      system ("pause");
      return 0;
}

This is what my output looks like:

Distance                  Power Loss
1.3477777e-308     0.000000000
1.3477777e-308     0.000000000
1.3477777e-308     0.000000000
1.3477777e-308     0.000000000
1.3477777e-308     0.000000000
1.3477777e-308     0.000000000
1.3477777e-308     0.000000000
1.3477777e-308     0.000000000
1.3477777e-308     0.000000000


Can anyone help?
0
Comment
Question by:gabos
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
rowansmith earned 500 total points
ID: 37713895
OK, so you are printing the "address" of miles and power_loss.  Not the values that are contained at those addresses.

You simply need to drop the &.
0
 
LVL 11

Expert Comment

by:rowansmith
ID: 37713923
I would suggest reading, (and of course understanding) this programming lesson.  I spent programming hours trying to learn these concepts :-)

Lesson 6: Pointers in C++
0
 

Author Closing Comment

by:gabos
ID: 37714087
That was the issue. I misunderstood the ampersand symbol. It is so much clearer now. Thank you.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
listing all functions in JavaScript 19 202
Image decoding from Camera 3 87
Recommendation vb6 to vb.net or others 14 149
Query Syntax 17 35
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A short article about problems I had with the new location API and permissions in Marshmallow
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question