Link to home
Start Free TrialLog in
Avatar of gabos
gabos

asked on

Simple C assignment

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?
ASKER CERTIFIED SOLUTION
Avatar of rowansmith
rowansmith

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rowansmith
rowansmith

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++
Avatar of gabos

ASKER

That was the issue. I misunderstood the ampersand symbol. It is so much clearer now. Thank you.