Receiving errors C2446 & C2440.

This is a discussion on Receiving errors C2446 & C2440. within the C++ Programming forums, part of the General Programming Boards category; I am trying to set this program up so that any grade that is below the average will have an ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    23

    Receiving errors C2446 & C2440.

    I am trying to set this program up so that any grade that is below the average will have an * placed next to it. When I compile I keep getting these two errors. 2446 is no conversion from double to int and 2440 is cannot convert from double to int. Anybody know what I am doing wrong?

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	const int MAXGRADES = 5;
    	int i, grade[MAXGRADES]= {0}, count = 0;
    	double Avg, sum = 0;
    
    	for (i=0; i < MAXGRADES; i++, count++)
    	{
    		cout << "Enter a grade: ";
    		cin  >> grade[i];
    
        if (grade[i]<0)
    {
        cout << "This is not a correct grade";
        break; 
     }
    	}
    
    	cout << endl;
    
    	for (i=0; i < count; i++)
    		cout << "grade " << i << " is " << grade[i] << endl;
    
    	cout <<"\nThe sum of the grades";
    	
    	for (i=0; i < count; i++)
    	{
    		
    		cout << "  " << grade[i];
    		sum = sum + grade[i];
    	}
    	cout << " are " << sum << endl;
    
    	if (count>0)
    		Avg = sum / count;
    	
    	cout << endl << setw(5) << "The average is: " << Avg << endl;
    
    	if (grade < Avg) // This is line receiving the errors!
    		cout << "*" << grade;
    
    	return 0;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    The problem is that grade is an array of int and you're trying to compare it with a double. That comparison doesn't exist, so you probably want to index the array first (at the very least).
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    23
    Would a for loop work? Maybe something like this:

    Code:
    for (i=0; grade[i] < Avg; i++)
    	{	
    		cout << "*" << grade[i];
    	}

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Maybe something like this
    Provided you can be sure that grade[i] will be less than Avg before i exceeds the boundaries of the array. I'm guessing you were going for something more like this:
    Code:
    for ( int i = 0; i < MAXGRADES; i++ ) {
      if ( grade[i] < Avg )
        cout<<'*'<< grade[i] <<'\n';
      else
        cout<< grade[i] <<'\n';
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing Errors
    By brietje698 in forum Networking/Device Communication
    Replies: 9
    Last Post: 12-10-2007, 11:17 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 10:14 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21