Question #4511

Question 1: Write a program, that during the entering of real resistance values prints the average resistance value.

Use a function Average_resistance() , to compute the average resistance.

make a PSD before writting the program.

Use a function Average_resistance() , to compute the average resistance.

make a PSD before writting the program.

Expert's answer

#include <iostream>

using namespace std;

double Average_resistance(){

int n = 0;

double sum = 0;

double val;

cout<<"Input real resistance values. Input -1 if you want to stop.

";

cin>>val;

while(val != -1){

n++;

sum += val;

cout<<"Current AV: "<< sum/n << endl;

cin>>val;

}

return sum/n;

}

int main(){

char input;

while(1){

cout<<"1 - count average resistance

";

cout<<"2 - exit

";

cin>>input;

if(input == '1'){

cout<<"---- Average value: "<<Average_resistance()<<" ----"<<endl;

} else if(input == '2'){

return 0;

} else {

cout<<"Wrong symbol! Try again

";

}

}

}

using namespace std;

double Average_resistance(){

int n = 0;

double sum = 0;

double val;

cout<<"Input real resistance values. Input -1 if you want to stop.

";

cin>>val;

while(val != -1){

n++;

sum += val;

cout<<"Current AV: "<< sum/n << endl;

cin>>val;

}

return sum/n;

}

int main(){

char input;

while(1){

cout<<"1 - count average resistance

";

cout<<"2 - exit

";

cin>>input;

if(input == '1'){

cout<<"---- Average value: "<<Average_resistance()<<" ----"<<endl;

} else if(input == '2'){

return 0;

} else {

cout<<"Wrong symbol! Try again

";

}

}

}

## Comments

## Leave a comment