Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple C assignment

Posted on 2012-03-13
3
Medium Priority
?
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
rowansmith earned 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Introduction to Processes
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

722 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