I'm trying to write a program that will calculate rations, max, min, total and average #. I'm told I can use #include <algorithm> but I don't know how to use it. I need it to spit out something similar to the following:


How many in the first category? 8 cats
How many in the second category? 12 dogs

cats                        8
                           dogs                      12
                           cat to dog ration    0.67
                           dog to cat ratio      1.50
                           max                        12
                           min                          8
                           total                        20
                           average                  10.00

I need to express ratios by exactly 2 decimal places and so I think I need to use the set precision, correct me if I'm wrong.

The program is supposed to run forever, but I ended it with return 0; because thats all I know how to close it with. I'm new at this C++ thing and I tried starting and have miserably failed. Here is a start of a new attempt and trying to get the average but I'm confused about how to calculate it.

Any help is greatly appreciated!

#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	int athletes;
	cout << "Please enter the number of athletes: ";
	int a1;
	cin >> athletes;

	int coaches;
	cout << "Please enter the number of coaches: ";
	int c1;
	cin >> coaches;

	double total = a1 + c1
	double average = (total)/ 2.0;
	cout << "average" << average << "\n";

return 0;
}

Read the rules, CODE TAGS.

Do you know about loops, like:

int    array[10];

/*populate*/

for(int i = 0; i < 10; i++)
    avrg += array[i];

arvrg /= 10;

That code assumes everything is always ten.

I'm working on that. However for the max, min our professor is not allowing us to use if/or statements so what other ways can I get the program to know which is max/min?

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.