Results 1 to 6 of 6

Thread: help me debug C++ program

  1. #1
    Join Date
    May 2006
    Beans
    76
    Distro
    Ubuntu 6.10 Edgy

    help me debug C++ program

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	int numStudents,
    		numTests,
    		total;
    	double average;
    	
    	cout<<"This program averages test scores.\n";
    	cout<<"For how many students do you have test scores? ";
    	cin >> numStudents;
    	
    	cout<<"How many test scores does each student have? ";
    	cin >> numTests;
    	
    	for (int student = 1; student <= numStudents; student++)
    	{
    		total = 0;
    		for (int test = 1; test <= numTests; test++)
    		{
    			int score;
    			cout<< "Enter score " <<test<< " for ";
    			cout<<"student " << student << ": ";
    			cin >> score;
    			total += score;
    		}
    		average = total / numTests;
    		cout << "The average score for student " << student;
    		cout << " is" <<average<< ". \n\n";
    	}
    	return 0;
    }

    // When i go to compile it via the terminal i get this error

    g++ testscores.cpp -o testscores
    testscores.cpp:36:3: warning: no newline at end of file

    // Anyone know whats wrong?
    ---Insert witty saying here---

  2. #2
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: help me debug C++ program

    Quote Originally Posted by stealth75711 View Post
    // When i go to compile it via the terminal i get this error

    g++ testscores.cpp -o testscores
    testscores.cpp:36:3: warning: no newline at end of file

    // Anyone know whats wrong?
    This isn't an error, it's a warning. Also, it tells you what the problem is, "warning: no newline at end of file". To fix, go to the last character of the last line of your file, and press enter. The last line of a source file should be a blank line is all.
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

  3. #3
    Join Date
    May 2006
    Beans
    76
    Distro
    Ubuntu 6.10 Edgy

    Re: help me debug C++ program

    Wow what a eronous thing to try to fix
    it works now thanks for tip
    Last edited by stealth75711; March 7th, 2007 at 04:11 AM.
    ---Insert witty saying here---

  4. #4
    Join Date
    Mar 2005
    Location
    Dunedin, NZ
    Beans
    559
    Distro
    Kubuntu 7.10 Gutsy Gibbon

    Re: help me debug C++ program

    C'mon what were you expecting?

    Not only did it tell you what the problem was, but the line and character number too.

    Just wait until you try to understand the compile errors for templated meta-programming.
    ACCU - for programmers who care

  5. #5
    Join Date
    Oct 2006
    Beans
    232

    Re: help me debug C++ program

    logic errors caused by pointers are fun too =) You never know what your gonna get

  6. #6
    Join Date
    Jul 2005
    Location
    Northern CA
    Beans
    634
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: help me debug C++ program

    Quote Originally Posted by thumper View Post
    C'mon what were you expecting?

    Not only did it tell you what the problem was, but the line and character number too.

    Just wait until you try to understand the compile errors for templated meta-programming.
    As many on this forum know, I was a CS professor for 21 years. This sort of thing was very common in lab. Students would call me over to help them debug their program, and I simply read what was printed on the screen for them.

    And when you get the compile errors all fixed, wait until you have to deal with code that seems to break randomly. Personally, I think it's great fun.
    Intel i7-920; Nvidia GT 220, 1GB; MSI X58 Pro-E; 6GB DDR; 64-bit mode.

Bookmarks

Posting Permissions

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