i have a question, why can't i do this, there are three errors and i don't know what they mean

#include<iostream.h>
float celsius_to_fahrenheit(float);
int main()
{
	float fahrenheit;
	float celsius=22.5;
	fahrenheit=celsius_to_fahrenheit(celsius);
	cout<<celsius<<"C="<<fahrenheit<<"F\n";
		return 0;
}
celsius_to_fahrenheit(float celsius)
{
	return(celsius*(9.0/5.0)+32.0);
}

Recommended Answers

All 5 Replies

Neither do we since you didn't tell us what they are.

#include<iostream>

float celsius_to_fahrenheit(float);
int main()
{
	float fahrenheit;
	float celsius=22.5;
	fahrenheit=celsius_to_fahrenheit(celsius);
	std::cout<<celsius<<"C="<<fahrenheit<<"F\n";
	return 0;
}
float celsius_to_fahrenheit(float celsius)
{
	return(celsius*(9.0/5.0)+32.0);
}

thanks for solving it but i have a question on why did i need the std:: before i cout and why did i need the float before when i already had declared celsius_to_fahrenheit as a float in the beginning before the main function

you needed std:: before cout because you didnt have using namespace std before your int main. and im pretty sure you had to include float again because the first was just declaring it as a function but im not sure on that.

>why did i need the std:: before i cout
Because every standard name is now placed inside the std namespace. To access one of those names, you have to get into the std namespace in one of three ways:

The using directive to open up all names within the scope:

#include <iostream>

int main()
{
  using namespace std;

  cout<<"Hello, world!\n";
}

The using declaration to open up only one name within the scope:

#include <iostream>

int main()
{
  using std::cout;

  cout<<"Hello, world!\n";
}

And explicit qualification:

#include <iostream>

int main()
{
  std::cout<<"Hello, world!\n";
}

>why did i need the float before when i already had declared
>celsius_to_fahrenheit as a float in the beginning before the main function
You need to specify a return type when declaring or defining a function. You did it when you declared celsius_to_fahrenheit, but you failed to do it when you defined celsius_to_fahrenheit.

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.