The problem is A voltage source supplies a load through a resistor. The
voltage source has a rating of 1000 volts and a power rating
of 10000 watts. The resistor is 5 ohms with a power ratings
of 118.975 watts. The resistance of the load may vary
randomly between 200 and 600 ohms. Using 100000 samples
calculate the following:

1-number of times the power rating of the resistor is exceeded
2-average power delivered by source
3-maximum power delivered by source
4-minimum power delivered by source

The output of the program should consist of 4 numbers,
each number being output on a separate line in the order
listed above. The numbers should be output with a precision
of 2. The seed is 259.

Ok im not sure where to plug in the value given but im pretty sure I got the code set up right

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <stdio.h>

using namespace std;

int main()
{
	double a,b,exceded, limit,average, max, min, powerRating, powerDelivered, power;

exceded = 0;
average = 0;
max = 0;
min = 0;
powerRating=(259*400)+200;

for (int i = 0; i < 100000; i++)
{
a = powerRating; //calculated with (rnd*400) + 200 as resistance)
if (a > limit)
{
exceded++;
}
b = powerDelivered;
average += b;

if (b > max)
{
max = b;
}

if (b < min)
{
min = b;
}
average = average / 100000;

cout << "# of times the power rating of the resistor is exceeded:"<<exceded ;
cout <<"Average power:"<<power;
cout <<"Maximum power:"<<max;
cout <<"Minimum power:"<<min;


}


}

Okay, wow... I'll be honest, not entirely sure what you are trying to do with this program. I sorta got lost in all the numbers, but, regardless, here's what I see.

All your cout lines at the end need to be on their own line right. Thus meaning they should look like this.

cout << "# of times the power rating of the resistor is exceeded:"<<exceded<<endl;
cout <<"Average power:"<<power<<endl;
cout <<"Maximum power:"<<max<<endl;
cout <<"Minimum power:"<<min<<endl<<endl;

The extra endl on the last line will help separate one set of output from the other sets of output so it is easier to read.

Now, general principle I like to work with. Try it with a small number of cases like 5. If you can get all five cases to work, only then make it run for a larger number. Right now, if you were to run this, it would run 10000 times before finishing. I'm assuming that's what you want it to do in the end, but when you don't even know if the code is correct, you don't cause you can't identify errors in 10000 outputs quickly. return 0; at the end of the function is the only other thing I see. You should really try to run it and see if it's giving out a result you expect.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.