I am writing a program using a linked list and I am almost to the point where I can compile and run it but I keep on getting this error message: error C2447: missing function header (old-style formal list?). What does it mean? I looked through the code but I cannot find anything wrong with it. Here is the code:

#include<iostream.h>

struct temperature_node
{
	int day;
	float temperature;
	temperature_node *next;
};

temperature_node *head_ptr;
temperature_node *current_ptr;

int get_temp(int days, float &temp);
void show_temps();
void remove_temps();
void add_temp(int days, float temp);
void move_c_to_end();

int main();
{
	int days;
	float temp;

	if(get_temp(days, temp))
	{
		head_ptr = new temperature_node;
		head_ptr->day = days;
		head_ptr->temperature = temp;
		head_ptr->next = NULL;
		while(get_temp(days, temp))
		{
			add_temp(days, temp);
		}
		show_temps();
		remove_temps();
	}
	return 0;
}

int get_temp(int days, float &temp)
{
	int keep_data = 1;

	cout << "enter the days for which you have data ";
	cin >> days;
	if(days != 0)
	{
		cout << "enter the temperature ";
		cin >> temp;
	}
	else
	{
		keep_data = 0;
	}
	return(keep_data);
}

void add_temp(int days, float temp)
{
	temperature_node *new_rec_ptr;
	new_rec_ptr = new temperature_node;

	new_rec_ptr->day = days;
	new_rec_ptr->temperature = temp;
	new_rec_ptr->next = NULL;

	move_c_to_end();
	current_ptr->next = new_rec_ptr;
}

void move_c_to_end()
{
	current_ptr = head_ptr;
	
	while(current_ptr->next != NULL)
	{
		current_ptr = current_ptr->next;
	}
}

void show_temps()
{
	current_ptr = head_ptr;

	do
	{
		cout << current_ptr->day << endl;
		cout << current_ptr->temperature << endl;
	} while(current_ptr != NULL);
}

void remove_temps()
{
	temperature_node *temporary_ptr;

	current_ptr = head_ptr;

	do
	{
		temporary_ptr = current_ptr->next;
		delete current_ptr;
		current_ptr = temporary_ptr;
	}while(temporary_ptr != NULL);
}

http://www.freewebs.com/yb2pls/index.htm

#include<iostream.h>

struct temperature_node
{
	int day;
	float temperature;
	temperature_node *next;
};

temperature_node *head_ptr;
temperature_node *current_ptr;

int get_temp(int days, float &temp);
void show_temps();
void remove_temps();
void add_temp(int days, float temp);
void move_c_to_end();

int main()
{
	int days;
	float temp;

	if(get_temp(days, temp))
	{
		head_ptr = new temperature_node;
		head_ptr->day = days;
		head_ptr->temperature = temp;
		head_ptr->next = NULL;
		while(get_temp(days, temp))
		{
			add_temp(days, temp);
		}
		show_temps();
		remove_temps();
	}
	return 0;
}

int get_temp(int days, float &temp)
{
	int keep_data = 1;

	cout << "enter the days for which you have data ";
	cin >> days;
	if(days != 0)
	{
		cout << "enter the temperature ";
		cin >> temp;
	}
	else
	{
		keep_data = 0;
	}
	return(keep_data);
}

void add_temp(int days, float temp)
{
	temperature_node *new_rec_ptr;
	new_rec_ptr = new temperature_node;

	new_rec_ptr->day = days;
	new_rec_ptr->temperature = temp;
	new_rec_ptr->next = NULL;

	move_c_to_end();
	current_ptr->next = new_rec_ptr;
}

void move_c_to_end()
{
	current_ptr = head_ptr;
	
	while(current_ptr->next != NULL)
	{
		current_ptr = current_ptr->next;
	}
}

void show_temps()
{
	current_ptr = head_ptr;

	do
	{
		cout << current_ptr->day << endl;
		cout << current_ptr->temperature << endl;
	} while(current_ptr != NULL);
}

void remove_temps()
{
	temperature_node *temporary_ptr;

	current_ptr = head_ptr;

	do
	{
		temporary_ptr = current_ptr->next;
		delete current_ptr;
		current_ptr = temporary_ptr;
	}while(temporary_ptr != NULL);
}

view my site http://www.freewebs.com/yb2pls/index.htm
and sign the guest book

I am writing a program using a linked list and I am almost to the point where I can compile and run it but I keep on getting this error message: error C2447: missing function header (old-style formal list?). What does it mean? I looked through the code but I cannot find anything wrong with it.

Notice the misplaced semicolon.

int main()[B];[/B]
{

I have a code snippet about singly / doubly linked lists if you run into any more trouble. Watch out for <iostream.h>, it should be 'updated' to

#include <iostream>
using namespace std;

as ive heard not all compilers / OS whatever support <iostream.h> anymore as it is non standardised! :)

Ok, I have made a few modifications and the program actually runs; but only to a certain point. Just so you have an idea, this program is supposed to consist of asking the user for the number of days that he\she has temperatures for and putting them in a linked list. when I display them at the end of the program the average temperature is suposed to be calculated also. I do not have anything that calculates the average as of yet but I'm not to worried. The problem I seem to be having now is that nodes are not being added. I think it is because of something in the get_temp function. any help is greatly appreciated. Here is the code:

#include <iostream>
using namespace std;

struct temperature_node
{
	int day;
	float temperature;
	temperature_node *next;
};

temperature_node *head_ptr;
temperature_node *current_ptr;

int day_counter = 0;

int get_temp(int days, float &temp);
void show_temps();
void remove_temps();
void add_temp(int days, float temp);
void move_c_to_end();

int main()
{
	int days = 0;
	float temp;

	if(get_temp(days, temp))
	{
		head_ptr = new temperature_node;
		head_ptr->day = days;
		head_ptr->temperature = temp;
		head_ptr->next = NULL;
	while(get_temp(days, temp))
		{
			add_temp(days, temp);
		}
	show_temps();
	remove_temps();
	}
return 0;
}

int get_temp(int days, float &temp)
{
	int keep_data = 1;

	if(days <= 0)
	{
		cout << "enter the number of days for which you have temperatures ";
        cin >> days;
	}

	while(day_counter != days)
	{
		cout << "Enter temperature for day " << day_counter + 1 << endl;
		cin >> temp;
		day_counter++;
	}

	if(day_counter == days)
	{
		keep_data = 0;
	}

	return(keep_data);
}

void add_temp(int days, float temp)
{
	temperature_node *new_rec_ptr;
	new_rec_ptr = new temperature_node;

	new_rec_ptr->day = days;
	new_rec_ptr->temperature = temp;
	new_rec_ptr->next = NULL;

	move_c_to_end();
	current_ptr->next = new_rec_ptr;
}

void move_c_to_end()
{
	current_ptr = head_ptr;

	while(current_ptr->next != NULL)
	{
		current_ptr = current_ptr->next;
	}
}

void show_temps()
{
	current_ptr = head_ptr;

	do
	{
		cout << current_ptr->day << endl;
		cout << current_ptr->temperature << endl;
	} while(current_ptr != NULL);
}

void remove_temps()
{
	temperature_node *temporary_ptr;

	current_ptr = head_ptr;

	do
	{
		temporary_ptr = current_ptr->next;
		delete current_ptr;
		current_ptr = temporary_ptr;
	}while(temporary_ptr != NULL);
}

this program is supposed to consist of asking the user for the number of days that he\she has temperatures for and putting them in a linked list.

Is this for an assignment?? otherwise if you are ASKING for the number of days why not declare an array with the given size:

data_type *data; // data_type is your data type (char/int/long ect....)

data = (data_type*)new data_type[size]; // size is the number of elements
delete [] data; // when you have finished with it delete it!

Yes, actually this is an assignment, :o but I don't want anybody to do it for me, I just need some hints. As you can probably tell I am very new at this, and I would not be posting here because I know that it is somewhat annoying to have everybody wanting someone else to do their homework for them. However I have a matter of days to get this done and I spend all my time on the computer working on it. The requirements for the program are: to write a program using a linked list that prompts the user for the days and temperatures and then calculates the average temperature. I have modified the get_temp function from the last post, and now the output displays the last day and the first temperature.

Here is the modified section of code:

int get_temp(int days, float &temp)
{
	int keep_data = 1;

    if(day_counter == days)
	{
		keep_data = 0;
	}
	else
	{
		days = day_counter + 1; // note that day_counter is a global variable
		cout << days;
		cout << "enter the temperature for day " << day_counter + 1 << endl;
		cin >> temp;
		day_counter++;
	}
	return(keep_data);
}

I do not know if anyone is even paying attention to this thread anymore but I found something wrong with the program nevertheless. In my show_temps function I forgot to add current_ptr = current_ptr->next; . That explains ALOT. Anyway, the program now displays all the temperatures the user adds but it only displays the last day. For example: Day: Temperature:
3 10
3 20
3 32.2
any ideas on how to fix this would be appreciated. If there is anyone out there reading this and they do not mind helping me, here is newest version of source code:

#include<iostream.h>

struct temperature_node 
{
	int day;
	float temperature;
	temperature_node *next;
};

int day_counter = 0;

temperature_node *head_ptr;
temperature_node *current_ptr;

int get_temp(int days, float &temp);
void show_temps();
void remove_temps();
void add_temp(int days, float temp);
void move_c_to_end();

int main()
{
	int days;
	float temp;

	cout << "enter the days for which you have data ";
    cin >> days;

	if(get_temp(days, temp))
	{
		head_ptr = new temperature_node;
		head_ptr->day = day_counter;
		head_ptr->temperature = temp;
		head_ptr->next = NULL;
	while(get_temp(days, temp))
		{
			add_temp(days, temp);
		}
	show_temps();
	remove_temps();
	}
return 0;
}

int get_temp(int days, float &temp)
{
	int keep_data = 1;

    if(day_counter == days)
	{
		keep_data = 0;
	}
	else
	{
		days = day_counter + 1;
		cout << days;
		cout << "enter the temperature for day " << day_counter + 1 << endl;
		cin >> temp;
		day_counter++;
	}
	return(keep_data);
}

void add_temp(int days, float temp)
{
	temperature_node *new_rec_ptr;
	new_rec_ptr = new temperature_node;

	new_rec_ptr->day = days;
	new_rec_ptr->temperature = temp;
	new_rec_ptr->next = NULL;

	move_c_to_end();
	current_ptr->next = new_rec_ptr;
}

void move_c_to_end()
{
	current_ptr = head_ptr;

	while(current_ptr->next != NULL)
	{
		current_ptr = current_ptr->next;
	}
}

void show_temps()
{
	current_ptr = head_ptr;

	do
	{
		cout << current_ptr->day << "         ";
		cout << current_ptr->temperature << endl;
		current_ptr = current_ptr->next;
	} while(current_ptr != NULL);
}

void remove_temps()
{
	temperature_node *temporary_ptr;

	current_ptr = head_ptr;

	do
	{
		temporary_ptr = current_ptr->next;
		delete current_ptr;
		current_ptr = temporary_ptr;
	}while(temporary_ptr != NULL);
}

Thanx :)

I forgot to add current_ptr = current_ptr->next;

Common linked list error. By discovering it at least you have learned something! im sure we were paying attention, but from experience i find that giving hints rather than complete solutions helps you to learn faster! - and that ive only had time to post VERY late at night and im too tired to wade through code lol :)

Yeah the whole current pointer bit made me feel pretty stupid. :o Anyway the program is still not displaying the proper day. I really appreciate the help you have been giving me, and I just wanna say thanx. If you do not really want to go through my code that is cool because I think I'll figure it out eventually, but if you do happen to go through it and find something you can give me a hint on that's even cooler :) I now can only get the last day to display and not any of the others.

thanx again

I dont understand the confusing days and day_counter code. It seems a little overcomplicated.

What about using a for loop:

temperature_node *header = NULL;
temperature_node *current = NULL;

temperature_node t = new temperature_node; // new node
t.day = -1; // make the header day -1 to differentiate it from the main list

header = current = &t; // point header, current = header at the moment

cout << "Enter the number of days for which you have data";
cin >> days;

for(int i = 0; i < days; i++)
{
    temperature_node t = new temperature_node; // make a new node
    t.day = i; // set day
    current->next = &t; // link this to the current node
    cout << "Enter Temperature";
    cin >> t.temperature;
}

float temp;

current = header;
while(current != NULL)
{
    current = current->next;
    temp += current->temperature;
}

temp /= days;

cout << "Average temperature = " << temp;

its not tested, its straight off the top of my head. Should work though....

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.