The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 2 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Could u please help me with this zybooks questions?
The root mean square is a specific kind of average which is used for various purposes. It is given by the formula shown here. This means that a sequence of values is squared and summed, then divided by the count of the values; the entire calculation is then square-rooted. Ask the user for input; stop when the user enters -1. Be sure to use the square and squareRoot functions you used in "Gentle" exercise 9.1. Here is a sample run:
Enter a positive number: 1
Enter a positive number: 2
Enter a positive number: 3
Enter a positive number: 4
Enter a positive number: 5
Enter a positive number: -1
The root mean square is 3.31662
Here is my code:
#include <iostream>
#include <math.h>
using namespace std;
int square(int);
double squareRoot(int);
int main()
{
int sum = 0;
int avg = 0; // To store mean of all the squared values
int counter = 0; // To store the no. of values entered by the user.
int n; // To store the value entered by the user.
double rms; // To store the final rooted mean value of the squared numbers
do{
cout << "Enter a positive number: "<<n<<endl;
cin >> n;
// If user enters the value for n as -1
if (n == -1)
break;
counter += 1; // Increment value of counter by 1 each time user enters a value
sum = sum + square(n); // Square and add
}while (n != -1); // Stop getting input when user enters -1
avg = sum / counter; // Mean of all the values
rms = squareRoot(avg); // RMS value
cout << "nThe root mean square is " << rms;
return 0;
}
// Function square() to return square of a number
int square(int n){
return n*n;
}
// Function squareRoot() to return the square root of a number
double squareRoot(int avg){
return sqrt(avg);
}
But didn't go though the zybooks, it said:
----------- He-----------llo----------- Si-----------r/M-----------ada-----------m -----------Tha-----------nk -----------you----------- fo-----------r y-----------our----------- in-----------ter-----------est----------- an-----------d b-----------uyi-----------ng -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------. P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll -----------be -----------qui-----------ckl-----------y