|
-
April 23rd, 2012, 10:02 PM
#1
ALMOST DONE.. LITTLE HELP please!
PHP Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double totalAverage[6];
int monkey, day;
const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;
double average [NUM_MONKEYS][NUM_DAYS];
double highest=0, lowest=30000;
cout << "Enter the amount of food in pounds eaten by the referred monkey.\n";
for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
{
for (day = 0; day < NUM_DAYS; day++)
{
cout << "Monkey " << (monkey + 1) << ", "
<< "Day " << (day + 1) << ": ";
cin >> average [monkey][day];
while ((average [monkey][day] < 0))
{
cout << "Please enter positive values.\n";
cin >> average [monkey][day];
}
}
cout << endl;
}
[B]cout << "Average of the three monkeys per day from day 1 to day 7\n";
totalAverage[0]=0;
for (day =0; day< NUM_DAYS; day++)
{
for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
{ totalAverage[day] += average[monkey][day];}
cout << "Average: " << totalAverage[day]/NUM_MONKEYS << endl;
}[/B]
//
for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
{
for (day =0; day< NUM_DAYS; day++)
{
if ((average [monkey][day]) > highest) //ESTE ESTA BIEN SEGUN YO ASI
highest = average [monkey][day];
}
//
}
for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
{
for (day =0; day< NUM_DAYS; day++)
{
if ((average [monkey][day]) < lowest ) // PERO ESTE ES EL DEL LOWEST Y PUES NOSE :S
lowest = average [monkey][day];
}
//
}
cout << fixed << showpoint << setprecision (2); // PARA QUE SEA DECIMAL POR EL DOUBLE
cout << "The highest amount is: " << highest << endl;
cout << "The lowest amount is: " << lowest << endl;
system ("PAUSE");
return 0;
}
WHEN YOU RUN and enter all the values, the part where the loop that say: cout << "Average of the three monkeys per day from day 1 to day 7\n"; does the average correct but on the third or fifth goes with power e
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|