help debugging

This is a discussion on help debugging within the C++ Programming forums, part of the General Programming Boards category; I'm supposed to open a .dat file and compute the average grade for some students, assign a letter grade and ...

  1. #1
    MB1
    MB1 is offline
    Registered User
    Join Date
    Feb 2005
    Posts
    38

    help debugging

    I'm supposed to open a .dat file and compute the average grade for some students, assign a letter grade and then cout the results.


    I'm getting: LNK2001: unresolved externatl symbol "double" Array

    Any suggestions, hints, etc?

    Code:
    #include <iostream>
    #include <fstream>
    #include <conio.h>
    #include <string>
    using namespace std;
    
    double Accum;
    double Average;
    double Array[];
    string LetterGrade;
    
    void Grade(double Array[], double i);
    
    int main(){
    	ifstream InFile;
    	string MyFile;//File to be opened
    	cout << "Please enter the file to open: ";
    	cin >> MyFile;
    	cout << endl;
    
    	InFile.open(MyFile.c_str());
    	if(!InFile.is_open()){
    		cout << "File does not exist!" << endl;
    		getch();
    		exit(0);
    		}
    
    	cout << MyFile;
    	int i = 0;
    	while(InFile >> MyFile){
    		Grade(Array, i);
    		}
    				
    	InFile.close();
    	getch();
    	return 0;
    }
    	void Grade(double Array[], double i){
    		for(int i = 0; i < 5; i++){
    			for(int r = 0; r < 5; r++){
    			Accum += Array[i];
    		}
    		
    		double Average = Accum / i;
    			if(Average > 89)
    				LetterGrade = "A";
    			else if(Average > 79)
    				LetterGrade = "B";
    			else if(Average > 69)
    				LetterGrade = "C";
    			else if(Average > 59)
    				LetterGrade = "D";
    			else
    				LetterGrade = "F";
    	cout << "The average grade for Sims is " << Average
    		<< " with a letter grade of " << LetterGrade  << '.';	
    		}
    	}

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    11
    Not sure since I don't use the Borland compilers needed for conio.h but when I remove that I get a message about unkown storage size of Array which may be your problem since its size needs to be initiated and unlike a vector it can't resize.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    32
    Give the array a const size, then grow where needed.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    You cannot really grow a static array. Simplest solution is to make the array plenty large enough to hold the maximum number of entries you might get. Do this by putting the appropriate number between the brackets on line 9. If your instructor/assignment/book doesn't specify a maximum, then you'll have to use dynamic memory, or a vector, which is the preferred C++ solution for dynamic arrays.

  5. #5
    MB1
    MB1 is offline
    Registered User
    Join Date
    Feb 2005
    Posts
    38
    Thank you-

    That fixed that problem.

    Our class uses: C++ Program Design by Cohoon and Davidson, 3rd edition. Don't like it too much.

    Can you recommend any books on C++ that are straightfarward?

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Accelerated C++ is usually recommended as the best pure C++ teaching book, but I don't know if it would meet your criteria of straightforward.

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Can you recommend any books on C++ that are straightfarward?
    "Ivor Horton's Beginning C++"

    It's a fairly difficult book, but it's excellent and it makes a great reference, so if you wanted to use it as companion book to look up things you don't understand, I would recommend it. Go to a bookstore and take a look at it and see what you think.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 09:48 AM
  2. Problem in debugging in Eclipse
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 08-21-2007, 09:53 AM
  3. Debugging Dev C++
    By tuurb046 in forum Tech Board
    Replies: 10
    Last Post: 08-16-2007, 12:51 PM
  4. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 07:35 PM
  5. debugging directx apps
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2003, 08:56 AM

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