CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2012
    Posts
    9

    Post Please little help me

    Hello, I got some errors from void and others. Is something wrong that?

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
    const int size=5;
    //array for students’ names
    string sNames[size];
    //get Names
    for(int i=0; i<5; i++)
    {
    cout << "Enter a student’s name: ";
    cin >> sNames[i];
    }
    
    //get scores
    double scoreForS[size][4], avg[size],sum[size]={0,0,0,0,0};
    
    for(int x=0;x<5;x++)
    {
    for(int y=0;y<4;y++)
    {
    cout<< "Enter the score for student " <<(x+1)<< " ";
    cin>>scoreForS[x][y];
    //input validation
    while(scoreForS[x][y]<0||scoreForS[x][y]>100)
    {
    cout << "Error.The range of score is 0 to 100. Reenter : ";
    cin >> scoreForS[x][y];
    }
    sum[x] += scoreForS[x][y];
    }
    }
    
    //drop lowest score
    
    double lowest[size];
    
    for(int a=0;a<5;a++)
    {
    lowest[a]= scoreForS[a][0];
    for(int b=1;b<4;b++)
    {
    if (lowest[a]>scoreForS[a][b])
    lowest[a]= scoreForS[a][b];
    
    }
    sum[a]-=lowest[a];
    }
    
    //get avg
    for(int c=0;c<5;c++)
    {
    avg[c]=sum[c]/3.0;
    }
    
    //scale
    char grade[size];
    for(int d=0;d<5;d++)
    {
    if(avg[d]>=90)grade[d]='A';
    else if(avg[d]>=80)grade[d]='B';
    else if(avg[d]>=70)grade[d]='C';
    else if(avg[d]>=60) grade[d]='D';
    else grade[d]='F';
    cout<<"\nStudent " << sNames[d] << " get " << grade[d];
    }
    
    system("pause");
    return 0;
    }
    
    void calcdata(int NUM_NAMES, double testscore[][NUM_TESTS])
    {
         
    double total;
    
    
    for (int row = 0; row < NUM_NAMES; row++)
    {
    
    	total = 0;
    
    	for (int col = 0; col < NUM_TESTS; col++)
    	
    		total += testscore[row][col];
    
    		average[row] = total / NUM_TESTS;
    	
    
    		if (average[row] < 60)
    			grade[row] = 'F';
    		else if (average[row] < 70)
    			grade[row] = 'D';
    		else if (average[row] < 80)
    			grade[row] = 'C';
    		else if (average[row] < 90)
    			grade[row] = 'B';
    		else if (average[row] < 100)
    			grade[row] = 'A';
    			
    }
    for (int i = 0; i < 5; i++)
    cout << "Student: " << name[i] <<" average: " << average[i] <<" grade: " << grade[i] << endl;
    }
    Anyone do u have idea?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Please little help me

    The errors I got with your code were all about undeclared identifiers. They seemed pretty self-explanatory to me.

  3. #3
    Join Date
    Oct 2012
    Posts
    9

    Re: Please little help me

    Quote Originally Posted by GCDEF View Post
    The errors I got with your code were all about undeclared identifiers. They seemed pretty self-explanatory to me.
    Hmm...Should I put integer with them on function prototype?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Please little help me

    Quote Originally Posted by dovip View Post
    Hmm...Should I put integer with them on function prototype?
    In Visual Studio, just double click on the first error and it will take you to the line of code causing the error (or very close to the offending line of code).

    If you don't know what the error means, paste the error in quotes in a bing or google search.

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Please little help me

    All your compile errors are in the calcdata function which is not currently being used. Comment out this function and the program will compile OK.

    Also, you have defined a const int to be the size of the used arrays. However, in the loops that access the arrays you are not using the const int but have the size hardcoded.

    I also take it that for each student you enter 4 scores. This number should be defined as a const int and used in the loops. I would also suggest that during the score input stage you state the score number required as well as the student number so the user knows exactly what score they are entering.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured