Here is the bit of my program that is causing me this grief:
float pcRRV(){ //calculate power consumption with rated resistor values
int i;
float pr=0,ptemp; //pr=power with rated values, ptemp=temporary power variable for for() loop
for(i=0;i<=RMAX;i++){
R=RRV[i];
ptemp=(V*V)/R; //power= V^2/R
pr=ptemp+pr; //add all power values (could also have added all resistors then calculated total power, either would require for() loop)
}
printf("Given the rated resistor values, the power consumed by the resistors, in series with a %dV source, is %fW.\n",V,pr);
puts("");
return pr; //need power value for part D
}
float pcARV(){ //calculate power consumption with actual resistor values
int i;
float pa=0,ptemp; //same formate as previous function
for(i=0;i<=RMAX;i++){
A=ARV[i];
ptemp=(V*V)/A;
pa=ptemp+pa;
}
printf("Given the actual resistor values, the power consumed by the resistors, in series with a %dV source, is %fW.\n",V,pa);
puts("");
return pa;
}
float powerpercentdif(){ //calculate percent difference between two power consumption values
float a,b;
float powerdif,powerave,percentdif;
a=pcRRV(); //use return value of pcRRV() as variable
b=pcARV(); //use return value of pcARV() as variable
powerdif=(a-b);
powerave=(a+b)/2;
percentdif=(powerdif/powerave)*100;
printf("The percent difference between the power consumption given the rated values and given the actual values of the resistors is %f%%.\n",percentdif);
}
So I have these 3 user defined functions, pcRRV(), pcARV(), and powerpercentdif(). in my main function I call all 3 in the order that you see, and the output should be as follows:
Given the rated resistor values, the power consumed by the resistors, in series with a 10V source, is 66.240997W.
Given the actual resistor values, the power consumed by the resistors, in series with a 10V source, is 64.273056W.
The percent difference between the power consumption given the rated values and given the actual values of the resistors is 3.015677%.
But what actually happens is this:
Given the rated resistor values, the power consumed by the resistors, in series with a 10V source, is 66.240997W.
Given the actual resistor values, the power consumed by the resistors, in series with a 10V source, is 64.273056W.
Given the rated resistor values, the power consumed by the resistors, in series with a 10V source, is 66.240997W.
Given the actual resistor values, the power consumed by the resistors, in series with a 10V source, is 64.273056W.
The percent difference between the power consumption given the rated values and given the actual values of the resistors is 3.015677%.
Now I don't want the output of the first two functions to be displayed twice. The easiest approach would be to not call the first two functions in main, but let their outputs be displayed when the 3rd function calls them. However, since this is for a class, one of the requirements is that the 3 functions I wrote must all be called in the main function to display their output, so I have to call all 3, but I don't want the output twice. Ultimately I'm wondering how to suppress the output of the 1st and 2nd functions when I assign them to variables in the 3rd function, because I just want to use their return values in that function, not have them display their full output. Thank you for the help in advance, and when I get a reply with a super simple answer I will be a combination of relieved/angry/depressed/happy. (I've been at this for a while) Thank you!
Aucun commentaire:
Enregistrer un commentaire