Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My program does not compile because of a line in my standard deviation function,

ID: 3626456 • Letter: M

Question

My program does not compile because of a line in my standard deviation function, I'm unsure how to fix it, could someone make it compile and make it calculate the standard deviation of my array correctly?

#include <iostream>
#include <cmath>

using namespace std;



void readMarks(int[],int&);
double pow(double n, int power)
{
double total = n;
for(int i = 2;i <= power ;i++)
{
total=total*n;
}
}
void showMarks(int[],int);

void deleteMarks(int[],int&);

double Average(int[],int);

double SD(int[],int);

void countOccurences(int[],int);

void pause();

void clear();




int main()

{

int marks[1000];

int size=0;

int choise;

do

{

cout<<" 0.Exit 1.Add a student Marks 2.List all student marks 3.Average 4.SD 5.Delete 6.Find Occurences"<<endl;

cout<<" Enter your choice-> ";

cin>>choise;

switch(choise)

{

case 1:readMarks(marks,size);break;

case 2:showMarks(marks,size);break;

case 3:cout<<endl<<Average(marks,size)<<endl;break;

case 4:cout<<endl;
SD(marks,size);
cout<<endl;break;

case 5:deleteMarks(marks,size);break;

case 6:countOccurences(marks,size);break;

case 0:exit(0);

}

pause();

clear();}while(true);

pause();

return 0;

}



void readMarks(int marks[],int &size)

{

int value;

cout<<"Enter marks : "<<endl;

cin>>value;

marks[size++]=value;

}



void deleteMarks(int marks[],int &size)

{

int value;

cout<<"Enter marks to be delete: ";

cin>>value;

int flag=false;

for(int i=0;i<size;i++)

if(marks[i]==value)

{

for(int j=i+1;j<size;j++)

marks[j-1]=marks[j];

flag=true;

size--;

break;

}

if(flag)

cout<<" Successfully deleted"<<endl;

else

cout<<" Not found in the list"<<endl;

}



void showMarks(int marks[],int size)

{

for(int i=0;i<size;i++)

cout<<marks[i]<<" ";

cout<<endl;

}



double Average(int marks[],int size)

{

double avg=0.0;

for(int i=0;i<size;i++)

avg+=marks[i];

return avg/size;

}



double SD(int marks[],int size)

{

double avg=Average(marks,size);

double sd=0.0;

for(int i=0;i<size;i++)
{
sd+=pow((marks[i]-avg),2);
cout << pow((marks[i]-avg),2) << "SD" << endl;
}

return sd;

}



void countOccurences(int marks[],int size)

{

int value;

cout<<" Enter marks to be find its occurence: ";

cin>>value;

int count=0;

for(int i=0;i<size;i++)

if(marks[i]==value)

count++;

cout<<"Number of occurences: "<<count;

}

void clear()

{

system("cls");

}

void pause()

{

cout<<endl;

system("pause");

}

Explanation / Answer

Sorry, for some reason when i copied and pasted into cramster it deleted some of the text for whatever reason... Here you go and ive read through it this time:


#include <iostream>
#include <cmath>

using namespace std;

void readMarks(int[],int&);

void showMarks(int[],int);

void deleteMarks(int[],int&);

double Average(int[],int);

double SD(int[],int);

void countOccurences(int[],int);

void pause();

void clear();



int main()

{

int marks[1000];

int size=0;

int choise;

do

{

cout<<" 0.Exit 1.Add a student Marks 2.List all student marks 3.Average 4.SD 5.Delete 6.Find Occurences"<<endl;

cout<<" Enter your choice-> ";

cin>>choise;

switch(choise)

{

case 1:readMarks(marks,size);break;

case 2:showMarks(marks,size);break;

case 3:cout<<endl<<Average(marks,size)<<endl;break;

case 4:cout<<endl;
SD(marks,size);
cout<<endl;break;

case 5:deleteMarks(marks,size);break;

case 6:countOccurences(marks,size);break;

case 0:exit(0);

}

pause();

clear();}while(true);

pause();

return 0;

}



void readMarks(int marks[],int &size)

{

int value;

cout<<"Enter marks : "<<endl;

cin>>value;

marks[size++]=value;

}



void deleteMarks(int marks[],int &size)

{

int value;

cout<<"Enter marks to be delete: ";

cin>>value;

int flag=false;

for(int i=0;i<size;i++)

if(marks[i]==value)

{

for(int j=i+1;j<size;j++)

marks[j-1]=marks[j];

flag=true;

size--;

break;

}

if(flag)

cout<<" Successfully deleted"<<endl;

else

cout<<" Not found in the list"<<endl;

}



void showMarks(int marks[],int size)

{

for(int i=0;i<size;i++)

cout<<marks[i]<<" ";

cout<<endl;

}



double Average(int marks[],int size)

{

double avg=0.0;

for(int i=0;i<size;i++)

avg+=marks[i];

return avg/size;

}



double SD(int marks[],int size)

{

double avg=Average(marks,size);

double sd=0.0;

for(int i=0;i<size;i++)
{
sd+=pow((marks[i]-avg),2);

}

sd/=(size-1);

sd=sqrt(sd);
cout <<sd << "<==SD" << endl;

return sd;

}



void countOccurences(int marks[],int size)

{

int value;

cout<<" Enter marks to be find its occurence: ";

cin>>value;

int count=0;

for(int i=0;i<size;i++)

if(marks[i]==value)

count++;

cout<<"Number of occurences: "<<count;

}

void clear()

{

system("cls");

}

void pause()

{

cout<<endl;

system("pause");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote