Question

In: Computer Science

WITHOUT USING POINTERS. This is C programming. I am writing a program which should calculate standard...

WITHOUT USING POINTERS. This is C programming. I am writing a program which should calculate standard deviation of an array of exam scores and then add the standard deviation to each array element. It should print the original array, the standard deviation, and the new rounded adjusted array. I included my question as a comment in the line of code that is giving me an issue. (Removing the a from E-x-a-m as Chegg doesn't allow the word.)

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


float calcstddev(float exmgrades[], int size)
{
   float sum =0.0;
   float mean;
   int temp;
   float variance;
   float stddev;
   float difference;


   for (temp=0;temp<size;++temp)
   {
       sum+=exmgrades[temp];
   }
   mean = sum/size;
   for (temp=0;temp<size;++temp)
   {
   stddev+=pow(exmgrades[temp]-mean,2);
   }
   stddev/=size;
   stddev=sqrt(stddev);
   return stddev;
}


float adjustscores(float exmgrades[],int size)
{
   float stddev=calcstddev(exmgrades,7);
   int temp=0;
   float adjustedscores[size];
  
   for(temp=0;temp<size;++temp)
   {
       adjustedscores[temp]+=exmgrades[temp]+stddev;
   }
   return adjustedscores; //////HERE is the line that gives me an error. It states:[Error] incompatible types when returning type 'float *' but 'float' was expected.    If I remove this line, my output for the adjusted array elements is .0f, so the data isn't passed to main. What should I do here? ///////////////////
}


int main()
{
   float exmgrades[]={90,95,90,82,80,87,92};
   float stddev=calcstddev(exmgrades,7);
   int size;
   int arrayprint;
   float adjustedscores[size];

   printf("The exm scores are: ");
   for (arrayprint = 0; arrayprint < 7; arrayprint++)
   {
    printf("%.0f ", exmgrades[arrayprint]);
   }


   printf("\nThe standard deviation is %.4f", stddev);
   printf("\nThe adjusted scores are: ");
   for (arrayprint =0; arrayprint <7; arrayprint++)
   {
    printf(".0f", adjustedscores[arrayprint]);
   }


}

Solutions

Expert Solution

Complete Working Code

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


float calcstddev(float exmgrades[], int size)
{
   float sum =0.0;
   float mean;
   int temp;
   float variance;
   float stddev;
   float difference;


   for (temp=0;temp<size;++temp)
   {
       sum+=exmgrades[temp];
   }
   
   mean = sum/size;
   
   for (temp=0;temp<size;++temp)
   {
                stddev+=pow(exmgrades[temp]-mean,2);
   }
   
   stddev/=size;
   stddev=sqrt(stddev);
   return stddev;
}


float adjustscores(float exmgrades[],int size)
{
   float stddev=calcstddev(exmgrades,7);
   int temp=0;
   float adjustedscores[size];
  
   for(temp=0;temp<size;temp++)
   {
           adjustedscores[temp] = 0; // change 3: initializing with 0, as it was giving garbage value
       adjustedscores[temp]+= exmgrades[temp] + stddev;
   }
   
   //change 2: printing the adjusted array in the function itself
   printf("\nThe adjusted scores are: ");
   
   for(temp=0; temp <size; temp++)
   {
                printf("%0.0f  ", adjustedscores[temp]);
   }
}


int main()
{
   float exmgrades[]={90,95,90,82,80,87,92};
   float stddev=calcstddev(exmgrades,7);
   int size;
   int arrayprint;
   float adjustedscores[size];

   printf("The exm scores are: ");
   
   for (arrayprint = 0; arrayprint < 7; arrayprint++)
   {
                printf("%0.0f ", exmgrades[arrayprint]);
   }


   printf("\nThe standard deviation is %.4f", stddev);
   
   adjustscores(exmgrades, 7); // change 1: added function call
   
}

Output Screenshot

I have made few changes in the code that has been mentioned in the code as comments:

change 1: Function call added to the main function

change 2: Function will not return the value, printing the adjusted array in the function itself.

change 3:initialize the elements of adjusted array, as it was giving the garbage value.

Please copy and paste the code and execute in your IDE to see the output.


Related Solutions

C Programming Run Length Encoder (Compression). I am writing a program that takes an image (from...
C Programming Run Length Encoder (Compression). I am writing a program that takes an image (from a text file) and looks for patterns of 2 or more duplicate values. The program should replace these values with the following pattern:  2 such characters followed by an Integer ( which represents number of occurrences of each character), followed by an asterisk. For example say the input of the non-compressed image was: ,,,,)H 7. i.e. it consists of four commas, one closed bracket, the...
I am writing a shell program in C++, to run this program I would run it...
I am writing a shell program in C++, to run this program I would run it in terminal like the following: ./a.out "command1" "command2" using the execv function how to execute command 1 and 2 if they are stored in argv[1] and argv[2] of the main function?
Develop a C program for matrix multiplication focusing on using malloc and pointers WITHOUT USING BRACKETS...
Develop a C program for matrix multiplication focusing on using malloc and pointers WITHOUT USING BRACKETS [] !! * DO not use [ ] 'brackets', focus on using malloc, calloc, etc... Program will ask user for the name of the text file to be read Read the datafile with format: 1 2 1 1 2 3 4 So the first three lines will represent m, n, p (Matrix A: m x n ||| Matrix B: n x p), follwing are...
I am Writing a C-Program to read and write files. but none of my code is...
I am Writing a C-Program to read and write files. but none of my code is working like it should be. Please fix all code and supply output response. Please try to use existing code and code in comments. But if needed change any code that needs to be changed. Thank you in advance //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void rfile(void); void wfile(void); struct personnel {...
Hi, (C programming) I am looking to write a program that will encrypt a text file...
Hi, (C programming) I am looking to write a program that will encrypt a text file automatically once program has opened, and have the option to decrypt it in a menu in my program. I have multiple text files that I need to encrypt, and would like if the program could encrypt all of them at once. I would also only like to decrypt the a text file once the name has been entered into a scanf function.
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
Integer Pointers Program and Analysis Demonstrate an understanding of basic C++ programming concepts by completing the...
Integer Pointers Program and Analysis Demonstrate an understanding of basic C++ programming concepts by completing the following: Program: Create a C++ program that asks the user to enter three integer values as input. Store the values into three different variables. For each variable, create three integer pointers that point to each value. Display the contents of the variables and pointers. In your program, be sure to use the new operator and delete operators to management memory. Program Analysis: Given your...
I need to write a C++ program that appends "not" into the string without using the...
I need to write a C++ program that appends "not" into the string without using the append method or any standard libraries. It should return the string if there isn't an "is" in it. Examples: is is = is not is not This is me = This is not me What is yellow? = What is not yellow? The sky is pink = The sky is not pink isis = isis What happened to you? = What happened to you?
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using...
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using malloc or calloc. Examples: Input: n = 5, A= {33,21,2,55,4} Output: {2,4,21,33,55} b) Write a function that declares an array of 256 doubles and initializes each element in the array to have a value equal to half of the index of that element. That is, the value at index 0 should be 0.0, the value at index 1 should be 0.5, the value at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT