Code:
#include <stdio.h>
#define R1 100
int R2;
int RL;
double V;
double VR2;
double VR1;
double VRL;
double PR2;
double PRL;
double I;
int
main (void){
int valid = 0;
while (valid == 0) { /*page 195*/
printf("Enter Power Supply Voltage Setting on the Programmable Power Supply in 0.1 volt increments (1-15)>\n");
scanf("%3lf", &V);
if (V > 15){
printf("\n Invalid value. The value must be 15 or less. \n");
valid = 0;}
else if (V < 1){
printf("\n Invalid value. The value must be one or greater. \n");
valid = 0; }
else
valid = 1;
}
int result = 0;
while (result == 0) {
printf("Enter Total Load Resistance in one ohm increments (100-5000)>\n");
scanf("%d", &RL);
if (RL > 5000 ){
printf("\n Invalid value. The value must be 5000 or less. \n");
result = 0;}
else if (RL < 100){
printf("\n Invalid value. The value must be 100 or greater. \n");
result = 0;}
else
result = 1;
}
int R2 = 5000;
while (R2 != 0){
R2 = 5000;
/*total current*/
I = V / (R2 + R1 + RL);
printf("Total current is %f amps. \n", I);
/*Voltage drop across R2*/
VR2 = (I * R2);
printf("Voltage of R2 is %f VDC. \n", VR2);
/*Voltage drop across R1*/
VR1 = (I * R1);
printf("voltage of R1 is %f VDC. \n", VR1);
/*Voltage drop across load*/
VRL = (I * RL);
printf("Voltage of load is %f VDC. \n", VRL);
/*Power drop across R2*/
PR2 = I * VR2;
printf("Power across R2 is %f watts. \n", PR2);
/*Power drop across load*/
PRL = I * VRL;
if (R2 != 0){
printf("Power is %f watts. \n", PRL);
R2 = R2 - 1;}
else
printf("Power is %f watts. Power is at Maximum level. \n", PRL);
}
return(0);}
I guess I am not understanding what changes need to be made. I need the loop to execute until R2 = 0. At that point I want the loop to end and the final statement of max power stated. Sorry, but three months ago I didn't even know what C programming was. You stated to make the changes stated but I guess I am not seeing what changes need to be made. I can be pretty dense sometimes while the obvious is biting my leg.