Special Prize to whoever finds the errors

This is a discussion on Special Prize to whoever finds the errors within the C++ Programming forums, part of the General Programming Boards category; Challenge problem: Where are the two errors??? Code: //Homework 18.4 //Benjamin Stollerman //CS 1050 #include <iostream.h> #include <fstream.h> #include <iomanip.h> ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    10

    Special Prize to whoever finds the errors

    Challenge problem: Where are the two errors???
    Code:
    //Homework 18.4
    //Benjamin Stollerman
    //CS 1050
    #include <iostream.h>
    #include <fstream.h>
    #include <iomanip.h>
    using namespace std;
    
    int main()
    {
    	//Define and initialize variables and 2D array
    	double lake[5][12];
    	double num_years[5];
    	double average[5];
    	double num=0;
    	//Attach object name
    	fstream powell_data;
    	// Associate object name to a file
    	powell_data.open("lake_powell.dat",ios::in);
    
    	/*Part A- Calculate the average elevation of the water level for each year
    	and for 5 year period*/
    
    	for(int k=0; k<12; k++)
    	//for loop
    	{
    		for(int j=0; j<5; j++)
    
    		powell_data>>lake_data[j][k];
    		//read in the data from above
    	}
    
    	for(int k=0; k<5;k++)
    	{
    		num_years[k] = 0;
    		for(int j=0; j<12; j++)
    			num_years[k] = lake[k][j]+1;
    		num += num_years[k];
    	}
    
    
    
    	for(int k=0; k<5; k++)
    	{
    		average[k]=0;
    		for(int j=0; j<12; j++)
    		{
    			if(lake[k][j] > (num_years[k]/12))
    			average[k] = average[k]+1;
    		}
    		cout<<"In "<<k+2000<<"The average elevation was: "<<(num_years[k]/12)<<endl;
    
    		cout<<"There were "<<average[k]<<" months above average"<<endl;
    	}
    	cout<<"The 5-year average elevation was: "<<(total/60)<<endl;
    	return 0;
    }
    Thankee very much!

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    First error: You posted a C++ question in a C forum.
    Second error: Your code uses deprecated header files.
    Bonus error: You didn't tell us what kind of error to look out for.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    10
    lol - at least you know that i'm no expert.
    thanks for taking a look anyways.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    What's the prize?

    If there is no actual prize, it's just a pathetic attempt to solicit special interest in your post.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Extra Bonus error: You're posting multiple topics about the same thing.

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Plus you're posting it in the wrong place each time!
    Ding ding ding!

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    51
    In
    Code:
    powell_data.open("lake_powell.dat",ios::in);
    the filename is wrong.

  8. #8
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Quote Originally Posted by benjamin923 View Post
    Challenge problem: Where are the two errors???
    Code:
    //Homework 18.4
    This made me laugh.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by pianorain View Post
    This made me laugh.
    Kids trying to get us to do their homework are morons because this kind of crap will bite them later on when they're unable to do a single thing during the tests. It gets even better if they get a degree for which they don't have the associated knowledge.

    I'm preaching to the choir, I know, but I'm hoping that the OP actually reads this if I mention it this way.

  10. #10
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by MacGyver
    Kids trying to get us to do their homework are morons because this kind of crap will bite them later on when they're unable to do a single thing during the tests. It gets even better if they get a degree for which they don't have the associated knowledge.
    I totally agree. I've run across programmers at places I've worked (VB .NET programmers to be precise) and they were total idiots. The software crashed constantly because they didn't account for typos in certain fields (like text boxes expecting numbers and you hit a letter - CRASH!).

    Edit: After a quick compile, I'll offer the suggestion that you check your variables and the scope they are used in.
    Last edited by Frobozz; 08-03-2007 at 04:05 PM.

  11. #11
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    I highly doubt that many individuals looking for a quick homework solution are going to be programming as a profession. Moreso, most are simply trying to get through the course, get the credit for it and put the misery behind them. We're geeks and freaks (and old men with nothing better to do) who actually like programming, but for many taking the course it's almost as distastful to them as gym class.

  12. #12
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Well the only other field I can think of that would require this is engineering. And if he can't handle this, he probably will have a hard time with engineering as well. For other degrees I can't imagine the language they force on them is C++. For my community college it was VBScript.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  3. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 01:28 AM
  4. errors using my parser- MSVC++ 6, bhtypes.h
    By AeroHammer in forum C++ Programming
    Replies: 6
    Last Post: 01-25-2005, 07:11 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