I actually went through the code and rewrote it. Here is what I have:

Code:

/****************************************************************/
/* CS263 Programming in C */
/* Assignment #3 Page 261 */
/* Written by: John Strange */
/* Date: 9/20/2012 */
/* */
/* */
/* Compute the power loss in a transmission line with a */
/* resistance of 0.05 ohms/mile. Compute the power loss if */
/* 500 kW of power is transmitted from a power generating */
/* station to cities at a distance of 20, 30, 40, 50,..., */
/* 100 miles at 100 V and 200 V. */
/* */
/****************************************************************/
/* */
/* dist = Distance */
/* */
/* page = Page number */
/* */
/* voltage = Voltage */
/* */
/* i = Current */
/* */
/* resist = Initial Resistance */
/* */
/* R = Total Resistance */
/* */
/* pwrLoss = Power Loss */
/* */
/****************************************************************/
#include <stdio.h>
#include <math.h>
int main()
{
int dist = 20;
int page = 0;
int voltage;
float i;
float resist = 0.05;
float R;
float pwrLoss;
for(voltage = 100; voltage <= 200; voltage += 100)
{
i = (500 / voltage);
page = page + 1;
printf(" ");
printf(" %d\n", page);
printf("\n Voltage: %d\n", voltage);
printf(" ____________ \n");
for(dist = 20; dist <= 100; dist += 10)
{
R = (resist * dist);
pwrLoss = (R * (i * i));
printf("\n Distance Power Loss");
printf("\n ________ __________");
printf("\n %d", dist);
printf(" %8.2f\n", pwrLoss);
}
}
return 0;
}

Here is the output I get when I run it...

Voltage: 100

____________

Distance Power Loss

________ __________

20 25.00

Distance Power Loss

________ __________

30 37.50

Distance Power Loss

________ __________

40 50.00

Distance Power Loss

________ __________

50 62.50

Distance Power Loss

________ __________

60 75.00

Distance Power Loss

________ __________

70 87.50

Distance Power Loss

________ __________

80 100.00

Distance Power Loss

________ __________

90 112.50

Distance Power Loss

________ __________

100 125.00

Voltage: 200

____________

Distance Power Loss

________ __________

20 4.00

Distance Power Loss

________ __________

30 6.00

Distance Power Loss

________ __________

40 8.00

Distance Power Loss

________ __________

50 10.00

Distance Power Loss

________ __________

60 12.00

Distance Power Loss

________ __________

70 14.00

Distance Power Loss

________ __________

80 16.00

Distance Power Loss

________ __________

90 18.00

Distance Power Loss

________ __________

100 20.00

The problem is that it is still not computing properly when the voltage is 200. Can anyone help me figure out why?

Thanks,

John

Originally Posted by

**Click_here**
Another for loop around that for loop.

Code:

for (dist=1; dist<=9; dist++)
{
...
}
Becomes
for (loop_counter=0; loop_counter<=2; loop_counter++)
{
for (dist=1; dist<=9; dist++)
{
...
}
i = ...;
}

Also note what oogabooga said about the data type.