Hey everyone. I've been working on a homework assignment to simulate a weather station responsible for recording hourly temps and reporting an average temp. I'm supposed to be passing an array to different functions to first get the temps and input them into the array. Then, compute the average temp from the array. Finally, display the array in a table format. I've got the code all typed up, but I keep getting an error that says... "function does not take 0 arguments" for each of my call to functions in the main..

So, here's the code I wrote that's not playing nicely. Also, attached the files for viewing too.

Header File

#ifndef Lab4_h
#define Lab4_h

	void GetTemperatures (int Temperatures[], int NumTemperatures);
	double ComputeAverageTemp (int Temperatures[], int NumTemperatures);
	void DisplayTemperatures (int Temperatures[], int NumTemperatures, double AverageTemp);

#endif

CPP File

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include "Lab4.h"

int main ()
{
	const int NumTemperatures = 24;
	int HourlyTemperatures[NumTemperatures] = {0};
	
	GetTemperatures ();
	ComputeAverageTemp ();
	DisplayTemperatures ();

	return 0;
}


	void GetTemperatures (int Temperatures[], int NumTemperatures)
	{
		int Count = 0;
		int CurrentTemp = 0;

		while (Count < 24)
		{
			cout << "Input hourly temp: ";
			cin >> CurrentTemp;

			Temperatures[++Count] = CurrentTemp;
		}
	
	}

	double ComputeAverageTemp (int Temperatures[], int NumTemperatures)
	{
		double AverageTemp = 0.0;
		int Count = 0;
		int Sum = 0;

		for (Count = 0; Count < 24; Count++)
		{
			Sum = Sum + Temperatures[Count];
		}

		AverageTemp = Sum / NumTemperatures;


		return AverageTemp;
	}

	void DisplayTemperatures (int Temperatures[], int NumTemperatures, double AverageTemp)
	{
		int Count = 0;

		cout << "*******************************\n";
		cout << "Hour\t\tTemperature\n";

		while (Count < 24)
		{
			cout << "0" << ++Count << ":00\t\t" << Temperatures[Count] << endl;
		}

		cout << "High Temp: \t\t\n";
		cout << "Low Temp: \t\t\n";
		cout << "Average Temp: \t\t" << AverageTemp << endl;
		cout << "*******************************\n";
	}

Recommended Answers

All 15 Replies

The problem is exactly what it is saying.
For example, you have a procedure prototyped as: [B]void[/B] GetTemperatures ([B]int[/B] Temperatures[], [B]int[/B] NumTemperatures); ...which clearly states that it requires two arguments.

but in main() you don't specify any arguments: GetTemperatures (); You must specify the arguments: GetTemperatures( HourlyTemperaturs, NumTemperatures ); I think the problem is that you are confusing multiple variables with the same name as a single variable. For example:

int answer = 42;

void print( int answer )
  {
  cout << "The answer is " << answer << endl;
  }

In this example, there are two variables named 'answer'. The first is a global variable and it has the value 42. The second is a temporary variable local to print(). In other words, it exists inside the function but nowhere else. Since it has the same name as the global variable, the local variable takes precedence (meaning you cannot use the global variable inside the function).

Hope this helps.

PS. You could use the global if you give its full name: cout << [B]::answer[/B] << endl;

commented: Key to helping me solve my problem. Thanks! +1

That makes perfect sense now, Duoas. That fixed my 0 argument problem, but now I'm having a problem when I Start Without Debugging.. I get the following error:

Debug Error!

Program: ...
Module ... ...\Labs\Lab 4\Lab4\debug\Lab4.exe
File:

Run-Time Check Failure #2 - Stack around the variable 'HourlyTemperatures' was corrupted.

(Press Retry to debug the application)

Abort Retry Ignore

Also, I can't seem to figure out why the average will display some funky number.. Attaching the files again so don't spam with code. If want the code to read lemme know and I'll post my current code. Thanks again for any help.

You exceed the array bounds by using the pre-increment operator in Temperatures[++Count] = CurrentTemp; change it to Temperatures[Count ++] = CurrentTemp;

You exceed the array bounds by using the pre-increment operator in Temperatures[++Count] = CurrentTemp; change it to Temperatures[Count ++] = CurrentTemp;

Ahh.. yep.. guess I need to pay more attention when using pre-increment.. Thanks. Any ideas on the averaging function?

cout << "Average Temp: \t\t" << AverageTemp << endl;

Is there some way that I could call the function there and just pass the value of AverageTemp?

I thought this would work but gives me a funky number still.. even if I just put all 1's which should give me 1 as the average..

cout << "Average Temp: \t\t" << ComputeAverageTemp << endl;

Ahh.. yep.. guess I need to pay more attention when using pre-increment.. Thanks. Any ideas on the averaging function?

cout << "Average Temp: \t\t" << AverageTemp << endl;

Is there some way that I could call the function there and just pass the value of AverageTemp?

I thought this would work but gives me a funky number still.. even if I just put all 1's which should give me 1 as the average..

cout << "Average Temp: \t\t" << ComputeAverageTemp << endl;

Not sure where this line is above, but it is not a function call. If ComputeAverageTemp is the function, you'll need some parentheses and you'll need to pass the parameters. Your code is short enough that I think posting your revised program would be easier than the attachments. I didn't know where the line above was in the program. If you post the whole revised program here rather than by attachment, you can refer to the line number of the function call and we'll get a better idea of what's changed.

Sorry lemme post the code again. :-) Anyway.. talking about line 87. Now I'm trying to call the function ComputeAverageTemp, but would I have to include all the parameters in () when calling even though I only want AverageTemp?

Header file

#ifndef Lab4_h
#define Lab4_h

	void GetTemperatures (int Temperatures[], int NumTemperatures);
	double ComputeAverageTemp (int Temperatures[], int NumTemperatures);
	void DisplayTemperatures (int Temperatures[], int NumTemperatures, double AverageTemp);

#endif

CPP File

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include "Lab4.h"

int main ()
{
	const int NumTemperatures = 24;
	int HourlyTemperatures[NumTemperatures] = {0};
	double AverageTemp = 0.0;

	cout << "*******************************\n";
	cout << "*    Welcome to CTU Weather   *\n";
	cout << "*    ----------------------   *\n";
	cout << "*                             *\n";
	cout << "*  Your source for up-to-date *\n";
	cout << "*     weather information!    *\n";
	cout << "*******************************\n\n\n";

	
	GetTemperatures (HourlyTemperatures, NumTemperatures);
	ComputeAverageTemp (HourlyTemperatures, NumTemperatures);
	DisplayTemperatures (HourlyTemperatures, NumTemperatures, AverageTemp);

	return 0;
}


	void GetTemperatures (int Temperatures[], int NumTemperatures)
	{
		int Count = 0;
		int CurrentTemp = 0;
		int TimerCount = 0;

		while (Count < 24)
		{
			if (CurrentTemp > -49 && CurrentTemp < 131)
			{
				cout << "Temperature at " << TimerCount++ << ":00? ";
				cin >> CurrentTemp;

				Temperatures[Count++] = CurrentTemp;
			}
			else
			{
				cout << "Incorrect temperature input...\n";
				cout << "Please input between -50 and 130 degrees...\n";
				cout << "Re-input temperature: ";
				cin >> CurrentTemp;
			}
		}
	
	}

	double ComputeAverageTemp (int Temperatures[], int NumTemperatures)
	{
		double AverageTemp = 0.0;
		int Count = 0;
		int Sum = 0;

		for (Count = 0; Count < 24; Count++)
		{
			Sum = Sum + Temperatures[Count];
		}

		AverageTemp = Sum / NumTemperatures;

		return AverageTemp;
	}

	void DisplayTemperatures (int Temperatures[], int NumTemperatures, double AverageTemp)
	{
		int Count = 0;

		cout << "\n*******************************\n";
		cout << "Hour\t\t   Temperature\n";

		while (Count < 24)
		{
			cout << Count++ << ":00\t\t\t" << Temperatures[Count] << endl;
		}

		cout << "High Temp: \t\t\n";
		cout << "Low Temp: \t\t\n";
		cout << "Average Temp: \t\t" << AverageTemp << endl;
		cout << "*******************************\n";
	}

Sorry lemme post the code again. :-) Anyway.. talking about line 87. Now I'm trying to call the function ComputeAverageTemp, but would I have to include all the parameters in () when calling even though I only want AverageTemp?

Header file

#ifndef Lab4_h
#define Lab4_h

	void GetTemperatures (int Temperatures[], int NumTemperatures);
	double ComputeAverageTemp (int Temperatures[], int NumTemperatures);
	void DisplayTemperatures (int Temperatures[], int NumTemperatures, double AverageTemp);

#endif

CPP File

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include "Lab4.h"

int main ()
{
	const int NumTemperatures = 24;
	int HourlyTemperatures[NumTemperatures] = {0};
	double AverageTemp = 0.0;

	cout << "*******************************\n";
	cout << "*    Welcome to CTU Weather   *\n";
	cout << "*    ----------------------   *\n";
	cout << "*                             *\n";
	cout << "*  Your source for up-to-date *\n";
	cout << "*     weather information!    *\n";
	cout << "*******************************\n\n\n";

	
	GetTemperatures (HourlyTemperatures, NumTemperatures);
	ComputeAverageTemp (HourlyTemperatures, NumTemperatures);
	DisplayTemperatures (HourlyTemperatures, NumTemperatures, AverageTemp);

	return 0;
}


	void GetTemperatures (int Temperatures[], int NumTemperatures)
	{
		int Count = 0;
		int CurrentTemp = 0;
		int TimerCount = 0;

		while (Count < 24)
		{
			if (CurrentTemp > -49 && CurrentTemp < 131)
			{
				cout << "Temperature at " << TimerCount++ << ":00? ";
				cin >> CurrentTemp;

				Temperatures[Count++] = CurrentTemp;
			}
			else
			{
				cout << "Incorrect temperature input...\n";
				cout << "Please input between -50 and 130 degrees...\n";
				cout << "Re-input temperature: ";
				cin >> CurrentTemp;
			}
		}
	
	}

	double ComputeAverageTemp (int Temperatures[], int NumTemperatures)
	{
		double AverageTemp = 0.0;
		int Count = 0;
		int Sum = 0;

		for (Count = 0; Count < 24; Count++)
		{
			Sum = Sum + Temperatures[Count];
		}

		AverageTemp = Sum / NumTemperatures;

		return AverageTemp;
	}

	void DisplayTemperatures (int Temperatures[], int NumTemperatures, double AverageTemp)
	{
		int Count = 0;

		cout << "\n*******************************\n";
		cout << "Hour\t\t   Temperature\n";

		while (Count < 24)
		{
			cout << Count++ << ":00\t\t\t" << Temperatures[Count] << endl;
		}

		cout << "High Temp: \t\t\n";
		cout << "Low Temp: \t\t\n";
		cout << "Average Temp: \t\t" << AverageTemp << endl;
		cout << "*******************************\n";
	}

Line 87 looks fine now to me. Perhaps change line 24 from this:

ComputeAverageTemp (HourlyTemperatures, NumTemperatures);

to this?

AverageTemp = ComputeAverageTemp (HourlyTemperatures, NumTemperatures);

There is no need to call ComputeAverageTemp at all in your DisplayTemperatures function as far as I can see. You've already called it once from main. You just didn't store the results of that function. Store it in AverageTemp, then pass AverageTemp to the Display function. No need to call ComputeAverageTemp twice.

Make it seem so easy, VernonDozier. :-O

Sorry to kinda put all the program problems in one thread, but I was reading more of my assignment description and my instructor wants me to use a pause function to "pause" the output. He gives the following code:

void Pause()
{
	cout << "Hit any key to continue...";
	cin.ignore(1);
}

How can that be used in a while loop that displays the data in the array? I read other threads that used both ways, but they had inputs and no output like me.. There is nothing being input so that function just goes into a never-ending loop. I've thought about using an if statement to use the pause, but don't know how to implement it in the while statement. If I use the following it just pauses after each output, which I don't want.. I want to pause after.. say 12 lines..

system ("PAUSE");

just add

Pause();

into the code where ever you want to stop .

And copy and paste the function somewhere outside main();

And it will work fine.

It works fine like that, but my problem is that I want it to stop after 12 lines scroll by in the while statement in lines 80-83 above. I thought maybe if I changed the number in the cin.ignore parameter it would scroll the lines and then stop, but it doesn't.

It works fine like that, but my problem is that I want it to stop after 12 lines scroll by in the while statement in lines 80-83 above. I thought maybe if I changed the number in the cin.ignore parameter it would scroll the lines and then stop, but it doesn't.

If you are trying to do something like this:

cin.ignore(12);

to make it display 12 elements, then pause, that isn't going to work. The above line of code tells C++ to ignore the next 12 characters from the keyboard, which is not what you want, it seems to me. See this link on ignore.
http://www.cplusplus.com/reference/iostream/istream/ignore.html

Keep your professor's idea and use 1 inside the parentheses:

cin.ignore(1);

The question is where to put this. Put this inside your display loop. You'll want an if statement in that display loop. Every twelfth time through that loop, execute that line. To get a feel for it, use a number like 4 in the beginning to get a feel for what happens, when it pauses, and what it does when you have different input (i.e. what happens when you just hit the return key when it pauses versus what happens when you hit a letter, then the return key). If you use 12, you won't get as good of a feel for it since there are only 24 elements in the array. Change it to 12 when you think you understand how it works. You'll likely use the mod operator (%) in this if statement along with the 4 (again, change it to 12 later). Keep in mind that you may have some characters in the input buffer left over from when you inputted the data so that could affect the "ignore" line results.

commented: Great help! +1

I see where you are going with cin.ignore.. I guess I just didn't exactly understand what it was doing because my instructor didn't explain. Now I understand with your explaination and the link. :)

Try for me to work on that if statement then. Thanks for the pointers again, VernonDozier.

Worked like a charm, VernonDozier! :cool: If you wouldn't have said likely use mod operator in the if statement I would have never gotten this to work the way I wanted. Props to you and everyone else that has helped me with this! I started out with 4 like you said and worked my way to a number that I felt would work how I like. Here's what I did with the mod operator:

while (Count < 24)
	{
		cout << "\t" << TimerCount++ << ":00\t\t\t" << Temperatures[Count++] << endl;

		if (Count % 24 == 12)
		{
			Pause();
		}
	}

Worked like a charm, VernonDozier! :cool: If you wouldn't have said likely use mod operator in the if statement I would have never gotten this to work the way I wanted. Props to you and everyone else that has helped me with this! I started out with 4 like you said and worked my way to a number that I felt would work how I like. Here's what I did with the mod operator:

while (Count < 24)
	{
		cout << "\t" << TimerCount++ << ":00\t\t\t" << Temperatures[Count++] << endl;

		if (Count % 24 == 12)
		{
			Pause();
		}
	}

Glad you got it to work. I was actually thinking of something like this:

if (Count % 4 == 0)
{
     Pause ();
}

which will pause after 0, 4, 8, 12, 16, 20. Change the 4 to a 12 and you'd get pauses after 0, 12, 24, 36, etc. The way you have it will pause after 12, 36, 60, etc. Which means it'll pause once after 12 since Count never makes it past 24.

I tried that at first, but went with what I have now because just wanted the single pause since everything fits nicely with just two. :cool: I'll keep yours in mind for the next time I run across a problem needing a series of pauses though. Thanks again, VernonDozier. BTW, added to your rep because you were so helpful with this problem.

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.