Question

Having some coding issues.

I can't seem to figure out why my calculation is coming out incorrect for the fourth column. For example, mathematically speaking the first row, columns 1-3:

​19, 68, 10. Using the specific equation: finalGrade = e1*.30 + e2*.30 + f*.40. I should get 30.1 in the 4th column but I get otherwise. See provided screenshot.

Please explain what I am doing wrong?

/* Program info:
Fill dd array 30 and 3 of grades
Double course[30][3](rows = students; col = exams)
1 - Fill it randomly
2 - fill a one dim array of 30 grades / students e1 * .30 + e2 * .30 + f * .40
*/


#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <ctime>
using namespace std;

int main()
{

double course[30][3];
int i, j; // i - (row) = students, j - (col) = exams


srand(time(0));

for (i = 0; i < 30; i++)
{
  for (j = 0; j < 3; j++)
  {
   course[i][j] = (rand() %100)+1;
  }
}


for (i = 0; i < 30; i++)
{
  double finalGrade = 0.0;
  for (j = 0; j < 3; j++)
  {
   cout << setw(4) << course[j][i] << ' '; // display table
   //finalGrade+= course[j];
   finalGrade = (course[i][j] * (.30)) + (course[i][j] * (.30)) + (course[i][j] * (.40)); //to multiply the first column by .30,
                      //multiply the second column by .30,
                      //and multiply the 3rd column by .40
                      //and sum them all together.

  }

  cout << setw(4) << finalGrade; // displays the final grade each student received for course on the 4th column.
  
  cout << endl;
}



system("pause");
return 0;
}

19 68 10 39 22 47 56 8 39 8 85 85 68 10 21 63 47 56 59 42 8 85 63 76 10 21 91 91 56 59 25 56 85 63 42 2Θ 21 91 88 57 59 25 27 3 63 42 76 47 91 88 78 59 25 27 51 75 42 76 91 86 88 78 84 87 27 51 83 26 76 91 56 44 78 844 48 51 83 89 87 91 56 20 1 84 4 29 34 3 94 56 20 57 26 4 29 84 42 89 3 51 66 20 57 3 8 29 84 58 41 3 51 35 58 3 47 31 83 89 57

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Problem is with using inner for loop.

2. In the current code, final grade is been calculating three times once for each j value.

3. Final grade has to be calculated using three columns (0, 1, 2)

_______________________________________________________________________________________________

Updated Code:

// studentGradesCode.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <ctime>

using namespace std;

int main()
{

   double course[30][3];
   int i, j; // i - (row) = students, j - (col) = exams


   srand(time(0));

   for (i = 0; i < 30; i++)
   {
       for (j = 0; j < 3; j++)
       {
           course[i][j] = (rand() %100)+1;
       }
   }

  
   for (i = 0; i < 30; i++)
   {
       double finalGrade = 0.0;
      
       //to multiply the first column by .30,
        //multiply the second column by .30,
        //and multiply the 3rd column by .40
        //and sum them all together.

       /*
           - Removed Inner for loop
           - Specify column number directly
           - Print all the values  
       */

       //Calculating final grade
       finalGrade = (course[i][0] * (.30)) + (course[i][1] * (.30)) + (course[i][2] * (.40));
      
       //Printing result
       cout << setw(4) << course[i][0] << setw(4) << course[i][1] << setw(4) << course[i][2] << "   " << setw(4) << finalGrade; // displays the final grade each student received for course on the 4th column.

       cout << endl;
   }


   system("pause");
   return 0;
}

______________________________________________________________________________________________

Sample Output:

cluserslsaibabu\documentslvisual studio 20101Proje 61 55 42 51.6 22 22 57 35 4 10 15.7 83 89 42 68.4 36 614 19 46 54 41.1 40

Add a comment
Know the answer?
Add Answer to:
Having some coding issues. I can't seem to figure out why my calculation is coming out...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the below matrixA, which you can copy and paste directly into Matlab.

    Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...

  • 1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand....

    1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...

  • RANGES FREQUENCY RELATIVE FREQUENCY CUMULATIVE REL. FREQ. 1 - 10 11 - 20 21 - 30 31 - 40...

    RANGES FREQUENCY RELATIVE FREQUENCY CUMULATIVE REL. FREQ. 1 - 10 11 - 20 21 - 30 31 - 40 41 - 50 51 - 60 61 - 70 71 - 80 81 - 90 91 - 100 '= 100 DATA VALUES?? SO, WHAT DOES A FREQUENCY TABLE TELL US? If you wrote each of the above data values on a ping pong ball,, put them in a jar and blindly pulled one out: What is the probability that this ball...

  • 8. The following data are scores from a Physics final administered to 34 students. 81 76...

    8. The following data are scores from a Physics final administered to 34 students. 81 76 93 99 47 67 69 72 83 88 56 62 91 94 98 63 77 84 98 75 79 67 73 65 89 86 91 85 97 73 56 92 88 83 Use the Chart below to construct a Frequency Distribution with 5 classes (15 pts) Class Tally (This column is optional.) Frequency

  • NUMBER OF PEOPLE 10.2 10.0 10.1 8.5 10.2 8.2 8 Source: United States Census. 11. In...

    NUMBER OF PEOPLE 10.2 10.0 10.1 8.5 10.2 8.2 8 Source: United States Census. 11. In the Sanitary District of Chicago, operating engineers are hired on of a competitive civil-service examination. In 1966, there were 223 appl for 15 jobs. The exam was held on March 12; the test scores are s arranged in increasing order. The height of each bar in the histogram next page) shows the number of people with the correspondin examiners were charged with rigging the...

  • I need to develop the 7 functions below into the main program that's given on top...

    I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...

  • Write a python nested for loop that prints out the following pattern 100 99 98 97...

    Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...

  • Calculate the range, mean, mode, median, Standard deviation Calculate the skewness and kurtosis for the above...

    Calculate the range, mean, mode, median, Standard deviation Calculate the skewness and kurtosis for the above data and interpret the data. The following is data collected from the daily salary employees of ZZ COMPANY.. 68 19 43 11 37 30 19 67 65 34 96 23 93 73 46 39 21 12 89 52 33 21 18 57 80 56 91 62 56 48 84 23 78 96 49 36 90 42 65 15 43 36 65 59 34 71...

  • QUESTION 27 Problem 5) Final scores of all the students in randomly selected 3 sections in...

    QUESTION 27 Problem 5) Final scores of all the students in randomly selected 3 sections in a course, "Statistical Methods at Sam Houston State University we presented below. There are 25 sections in total Section 3: (69.92, 66, 81, 76, 55, 70, 83, 68, 57, 80, 66, 69, 55, 88, 70, 70, 70, 56, 50) Section 6: (10, 73, 88, 58, 89, 69, 63, 76, 87, 82, 97, 76, 66, 95, 84, 88, 82, 81, 68, 89) Section 9: (30,...

  • QUESTION 33 Problem 5) Final scores of all the students in randomly selected 3 sections in...

    QUESTION 33 Problem 5) Final scores of all the students in randomly selected 3 sections in a course, "Statistical Methods I at Sam Houston State University are presented below. There are 25 sections in total Section 3: (69.92, 66, 81, 76, 55, 70, 83, 68, 57, 80, 66, 69, 55, 88, 70, 70, 70,56,50) Section 6: [10, 73, 88, 58, 89, 69, 63, 76, 87, 82, 97, 76,66,95, 84, 88, 82, 81, 68, 89) Section 9: (30, 85, 76, 73,92,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT