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?
Programming Languages-OtherProgramming

Avatar of undefined
Last Comment
gabos

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
rowansmith

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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++
gabos

ASKER
That was the issue. I misunderstood the ampersand symbol. It is so much clearer now. Thank you.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck