Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7439627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:43:58+00:00 2026-05-29T10:43:58+00:00

I am learning about pointers and arrays in class. My trouble is in the

  • 0

I am learning about pointers and arrays in class. My trouble is in the dupScore function.
I am trying to find the number of students who have the same score. scoreArrays element number identifys the student and holds the score.

I want to create a new array to use the students score as the index to the array. I get a red squiggly under scoreArrays though. The error is “expression must be integral or enum”

for(int count = 0; count < maxStudents; count++)
        comparisonArray[scoreArray[count]]++;

Here is my whole code.

#include <iostream>
using namespace std;

const int maxStudents = 30;
void readScores(double[]);
void gradeCounter(double[],int&,int&,int&,int&,int&);
int dupScore(double[]);
void readoutFunc(double[], int, int, int, int, int, int);

int main()
{
    int As = 0, Bs = 0, Cs = 0, Ds = 0, Fs = 0; // Distribution of scores
    int sameScore = 0;

    double scoreArray[maxStudents];
    readScores(scoreArray);//Read in Scores
    gradeCounter(scoreArray, As, Bs, Cs, Ds, Fs);//Count letter grades
    sameScore = dupScore(scoreArray);//Detect duplicate scores

    system ("PAUSE");
    return 0;
}


void readScores(double scoreArray[])
{
    double *scorePTR;
    scorePTR = scoreArray;

    for(int count = 0; count < maxStudents; count++)
    {
        cout<<"Please enter score for student "<<count+1<<" or -999 to end.\n";
        cin>>*(scorePTR+count);
        if(*(scorePTR+count) == -999)
        break;
    }
 }



void gradeCounter(double scoreArray[],int &As,int &Bs,int &Cs,int &Ds,int &Fs)
{
    double *scorePTR2;
    scorePTR2 = scoreArray;

    for(int count = 0; count < maxStudents; count++)
    {
        if(scoreArray[count] >= 90)
            As+=1;
        else if(*(scorePTR2+count) >= 80 && *(scorePTR2+count) < 90)
            Bs+=1;      
        else if(*(scorePTR2+count) >= 70 && *(scorePTR2+count) < 80)
            Cs+=1;
        else if(*(scorePTR2+count) >= 60 && *(scorePTR2+count) < 70)
            Ds+=1;
        else if(*(scorePTR2+count) >= 0 && *(scorePTR2+count) < 60)
            Fs+=1;
    }
}

int dupScore(double scoreArray[])
{
    const int maxGrade = 101;
    double comparisonArray[maxGrade];
    int sameScores = 0;


    for(int count = 0; count < maxStudents; count++)
        comparisonArray[scoreArray[count]]++;

    for(int count2 = 0; count2 < maxGrade; count2++)
    {
        if(comparisonArray[count2] > 0)
            sameScores+=1;
    }


        return sameScores;

}

void readoutFunc(double scoreArray[], int As, int Bs, int Cs, int Ds, int Fs, int sameScore)
{
        int numofStudents = 0;
    for(int count = 0; scoreArray[count] >= 0; count++)
    { 
        numofStudents += 1;
    }
    cout<<"\n\nReport";
    cout<<"\n---------";
    cout<<"\nNumber of students: "<<numofStudents;
    cout<<"\nNumber of As: "<<As;
    cout<<"\nNumber of Bs: "<<Bs;
    cout<<"\nNumber of Cs: "<<Cs;
    cout<<"\nNumber of Ds: "<<Ds;
    cout<<"\nNumber of Fs: "<<Fs;

    cout<<"\n\n"<<sameScore<<" students have the same score."
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:43:59+00:00Added an answer on May 29, 2026 at 10:43 am

    scoreArray is defined as double[] so scoreArray[count] will give you a double. You’ll need an integer to be able to reference an element from the comparisonArray.

    for(int count = 0; count < maxStudents; count++)
    comparisonArray[(int)scoreArray[count]]++;

    That will fix the problem you are currently facing, but it will also lose a lot of precision. You might look at changing the double[] to an int[] if grades are always integers. Otherwise you might need to look at a different method of matching elements of the scoreArray.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to C and I have some problems learning about pointers.
I am just now learning about function pointers and, as I was reading the
I am learning C programming and I have a simple question about pointers... I
I am learning about pointers and the new operator in class. In my readArray
I'm currently learning about pointers in my C++ Algorithms class and while I understand
I am writing a program for a class assignment on learning about pointers and
Very confused over this. I've just started learning about pointers and have now decided
I learning to use Pointers. I have a few questions about an exercise code
I have been learning about the basics of C# but haven't come across a
I am just learning about app.config in respect of creating custom sections. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.