I am taking a intro programming course currently. I am stumped by my current assignment. The program is suppose to do the following using functions only (no other code allowed in main):

1. Get data from an input file and put into a parallel array.
2. Find and display the high temp.
3. Find and display the low temp.
4. Calculate the average temp and display.

I am getting a run time error. Please give me some advice on what is going wrong.

I attached two files to this post. One is the source code (cityTemps) and the other is the input file (temperatures). Thanks a lot.

Recommended Answers

All 5 Replies

Start with

readData(cityArr, tempArr);
//   	getHighTemp(cityArr, tempArr);
//  	getLowTemp(cityArr, tempArr);
//	calcAvgTemp(tempArr);

Does it crash?

How about

readData(cityArr, tempArr);
   	getHighTemp(cityArr, tempArr);
//  	getLowTemp(cityArr, tempArr);
//	calcAvgTemp(tempArr);

Maybe this

readData(cityArr, tempArr);
   	getHighTemp(cityArr, tempArr);
  	getLowTemp(cityArr, tempArr);
//	calcAvgTemp(tempArr);

Understand?

Or you could use a debugger, which would save all the edit the code, try it and repeat.

Thanks. I tried that. When I run the first function by itself it claims the input file is not opening. I am try to figure out why right now.

Look at the spelling of the file name you are attempting to open.

A good idea is to have your reading function return a value indicating success (or how much success) or failure - use that to determine if the program should even go on to attempt processing the data.

Darn, I feel like a fool. Thanks!

Darn, I feel like a fool. Thanks!

Don't beat yourself up. I think most of us do something like this from time to time. It's hard to proofread your own writing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.