Question

NO POINTERS TO BE USED. This is C programming. I am trying to make a function...

NO POINTERS TO BE USED. This is C programming.
I am trying to make a function to calculate standard deviation from a hard coded array. Why is my function not returning my stddev value back to main? I keep getting an error saying that stddev is undeclared.

#include <stdio.h>
#include <math.h>


float calcstddev(float examgrades[], int size)
{
   float sum =0.0;
   float mean;
   int temp;
   float variance;
   float stddev;
   float difference;
   for (temp=0;temp<size;++temp)
   {
       sum+=examgrades[temp];
   }
   mean = sum/size;
   for (temp=0;temp<size;++temp)
   {
   stddev+=pow(examgrades[temp]-mean,2);
   }
   stddev/=size;
   stddev=sqrt(stddev);
   return stddev;
}

int main()
{
  
   float examgrades[]={90,95,90,82,80,87,92};
   calcstddev(examgrades,7);
   printf("The standard deviation is %.4f", stddev);
}

Homework Answers

Answer #1

Without pointer there is only one method get value by a function(Not main) which is to collect data returned by function in a varaible.

Code with small modication is given:

#include <stdio.h>
#include <math.h>


float calcstddev(float examgrades[], int size)
{
   float sum =0.0;
   float mean;
   int temp;
   float variance;
   float stddev;
   float difference;
   for (temp=0;temp<size;++temp)
   {
       sum+=examgrades[temp];
   }
   mean = sum/size;
   for (temp=0;temp<size;++temp)
   {
   stddev+=pow(examgrades[temp]-mean,2);
   }
   stddev/=size;
   stddev=sqrt(stddev);
   return stddev;
}

int main()
{
  
   float examgrades[]={90,95,90,82,80,87,92};
   float stddev=calcstddev(examgrades,7);
   printf("The standard deviation is %.4f", stddev);
}

If you didn't mean that in question please comment.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Can you translate this C code into MIPS assembly with comment? #include <stdio.h> #include <math.h> #include...
Can you translate this C code into MIPS assembly with comment? #include <stdio.h> #include <math.h> #include <stdlib.h> double fact (double); void main () { int angle_in_D; double term, angle_in_R; float sine = 0; unsigned int i = 1; double sign = 1; int n = 1000; printf ("Please enter an angle (Unit: Degree): "); scanf ("%d", &angle_in_D); angle_in_R = angle_in_D * M_PI / 180.0; do { term = pow(-1,(i-1)) * pow (angle_in_R, (2*i - 1)) / fact (2*i - 1);...
C++, I am not able to get this program to function correctly, ie not launching at...
C++, I am not able to get this program to function correctly, ie not launching at all #include <iostream> #include <stdio.h> int insert(int num, int location) { int parentnode; while (location > 0) { parentnode =(location - 1)/2; if (num <= array[parentnode]) { array[location] = num; return; } array[location] = array[parentnode]; location = parentnode; } array[0] = num; } int array[100], n; using namespace std; main() { int choice, num; n = 0; while(1) { printf("1.Insert the element \n"); printf("2.Delete...
Hello, I feel like I am super close but I can not figure out why my...
Hello, I feel like I am super close but I can not figure out why my C++ code it not displaying the proper medium. Thank you! Here is an example of the output: Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7} Output : Mean = 4.5 Median = 4.5 Code so far:   #include <iostream> using namespace std; int main() { int a[100]; int n,i,sum=0; float mean, medium; //read array size // read array cout<<"Enter array size:...
I am trying to write a program in C language but keep running into errors. Any...
I am trying to write a program in C language but keep running into errors. Any help would be awesome. here is my code I have so far. #include <stdio.h> #include <conio.h> #include <string.h> int main(){    int lenght, i = 0, state = 0;    char line[100];    printf("enter the string for checking of comment line: \n");    gets(line);    while(i < strline(line)){        switch(state){            case 0: if (line[i] == '/'){               ...
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input....
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input. The first integer indicates the number of values that will follow. Read that many values, and return their sum, ignoring any additional values that may follow. However, if there are fewer integers than specified in the input, print "Error" and terminate. Hint: int n, success; ... success = scanf("%d", &n); // FIRST INTEGER INPUT reads an integer from stdin, returning 1 if the integer...
C Programming I am trying to also print the frequency and the occurrence of an input...
C Programming I am trying to also print the frequency and the occurrence of an input text file. I got the occurrence to but cant get the frequency. Formula for frequency is "Occurrence / total input count", this is the percentage of occurrence. Can someone please help me to get the frequency to work. Code: int freq[26] = {0}; fgets(input1, 10000, (FILE*)MyFile); for(i=0; i< strlen(input); i++) { freq[input[i]-'a']++; count++; } printf("Text count = %d", count); printf("\n"); printf("Frequency of plain text\n");...
I'm trying to find a code to check the occurrences of the word or string I...
I'm trying to find a code to check the occurrences of the word or string I wrote my own code but it's not working can you please help and fix my code #include <stdio.h> #include <string.h> #define MAX_SIZE 100 // Maximum string size int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE]; printf("Enter any string: "); gets(str); printf("Enter word to search occurrences: "); gets(tosearch); int cursor = 0; int i = 0; int stringLen = 0; int searchLen = 0; int count1;...
We see that this computes the product of two matrices. Add a new kernel code, called...
We see that this computes the product of two matrices. Add a new kernel code, called sum, to compute the sum of the two matrices. #include <stdio.h> #include <math.h> #include <sys/time.h> #define TILE_WIDTH 2 #define WIDTH 6 // Kernel function execute by the device (GPU) __global__ void product (float *d_a, float *d_b, float *d_c, const int n) {    int col = blockIdx.x * blockDim.x + threadIdx.x ;    int row = blockIdx.y * blockDim.y + threadIdx.y ;    float...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using pointers correctly and deleting memory properly? #ifndef DYNAMICARRAY_H #define DYNAMICARRAY_H #include <cstdlib> #include <iostream> using namespace std; // Node class class Node { int data; Node* next; Node* prev; public: Node(); Node(int); void SetData(int newData) { data = newData; }; void SetNext(Node* newNext) { next = newNext; }; void SetPrev(Node* newPrev) { prev = newPrev; }; int getData() { return data; }; Node* getNext()...
Need this in C programming please with correct output of the code and also please attach...
Need this in C programming please with correct output of the code and also please attach the screenshot of it // In this problem, we try to find and fix a bug in the following code. // The following code is trying to calculate a sum that will converge to PI(3.141592....) // when the number of items goes to infinity. // This following code is based on the fact that // that sum of items 8/((4*i +1)*(4*i +3)) for i...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT