fixd
public text v1 · immutable/*
* Kevin Stewart
* COSC 1436, Northeast
* Windows XP SP2 - Dev-C++
* Lab 6 , 9:21am, 5/3, 2007
*
* Program Description---------------------------------
* Stores values into an array and computes them
*
* Program Design--Pseudocode
* declartions of varibles
begin
* end
*/
#include <iostream>
#include <iomanip>
using namespace std;
int main () //start of main function
{
int num_list[9];
cout<<"Enter values into an array" << endl;
cout<<" " << endl;
cout<<" " << endl;
for(int i=0;i<10;i++)
{
cout<<"Enter value " << endl;
cin>>num_list[i];
}
//Values
cout<<" " << endl;
cout<<" " << endl;
cout << "---------------------------------------------------" << endl;
cout<<"Values" << endl;
for(int i=0;i<10;i++)
{
cout << num_list[i] << endl;
}
cout<<" " << endl;
//precent of total
// Set total = 0
int total = 0;
float pre, pot;
int smallest, largest;
for(int i=0;i<10;i++)
{
total += num_list[i];
}
cout << "Percent of Total" << total << endl;
for(int i=0;i<10;i++)
{
// type cast num_list to a float, or else
// it will try to divide two ints, always
// resulting in 0
pre = (float)num_list[i] / total;
// not sure what this means,
// but you always need it for setprecision
cout.setf(ios::fixed);
pot = pre * 100;
// set decimal precision to two places
cout<<setprecision(2) << pot << "%" << endl;
}
//RANGE
cout << " " << endl;
for(int i=0;i<10;i++)
{
for(int x=0; x<10; x++)
{
if (num_list[i] < smallest || i==0)
smallest = num_list[i];
if (num_list[i] > largest || i==0)
largest = num_list[i];
}
}
cout << "Values used range from " << smallest << " to " << largest << endl;
//AVERAGE
cout<<" " << endl;
double average = total / 10;
cout << "Average of the Ten Values = " << average << endl;
cout<<" " << endl;
//above average
int above_average;
cout << "Values above the Average" << endl;
for(int i=0;i<10;i++)
{
if (num_list[i]>average)
{
cout << num_list[i] << endl;
}
}
cout<<" " << endl;
//class info
cout << "KStewart S809L6.cpp" << endl;
cout << "Lab#6 - NE 5/3/07" << endl;
cout << "---------------------------------------------------" << endl;
system ("pause");
return 0;
}