Created
May 1, 2016 21:50
-
-
Save batmantec/24d4253b12f880f4f2dee2805f1574b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using std::endl; | |
using std::cout; | |
using std::cin; | |
float getTotal (float nums[], int allNums){ | |
float answer=0.0; | |
for (int i = 0; i < allNums; i++) { | |
answer=answer+nums[i]; | |
} | |
return answer; | |
} | |
float getAverage (float nums[], int allNums){ | |
float answer= getTotal (nums, allNums)/allNums; | |
return answer; | |
} | |
float getDev (float nums[], int allNums){ | |
float sum=0.0; | |
for (int i = 0; i < allNums; i=i+1) { | |
float answer=pow(getAverage(nums, allNums)- nums[i], 2); | |
sum=sum+answer; | |
} | |
float a=sqrt(sum/(allNums-1)); | |
return a; | |
} | |
int main (){ | |
int allNum=10, i, count = 1; | |
float a[allNum], total, average, standard; | |
cout << "Calculates total, average, and standard deviation of 10 numbers." << endl; | |
for (i=0; i < allNum; i++) { | |
cout <<"Type the " << count << " number: "<<endl; | |
count++; | |
cin >>a[i]; | |
} | |
total= getTotal(a, allNum); | |
average= getAverage(a, allNum); | |
standard= getDev(a, allNum); | |
cout <<"The total is: "<<total<<endl; | |
cout <<"The average is: "<<average<<endl; | |
cout <<"The standard deviation is: "<<standard<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment