`

#include<iostream.h>
#include<conio.h>

void main()

int n;
int f,c;
cout<<"1:enter the faranheit value to convert:";
cin>>f;
cout<<"2:enter the celscious value to convert:";
cin>>c;
clrscr();
switch(n)
{
case 1:
    ftoc(c);
    break;
case 2:
    ctof(f);
    break;
default:
     cout<<"try 1 or 2";

}
getch();
}

float ctof(float d)
{
  d=d*9/5+32;
  cout<<"faranheit value is:"<<d;
  return d;
}
float ftoc(float f)
{
f=(f-32)*5/9;
cout<<"celcious value is:"<<f;
return f;
}

`
okay this must looks stupid but I am new to the prograaming...why I am getting error "function "ftoc and ctof" shold have prototype"

Recommended Answers

All 3 Replies

You must declare a function before you call it, at lines 16/19 you respectively call ftoc/ctoc but this is the first time the compiler has seen those functions (it reads the file line by line).

All you need to do is arround line 3 add the code lines

static float ctof(float d);
static float ctof(float d);

This tells the compiler about those functions, their parameters what they return and allows the calls at line 16/19. This is part of the stricter type checking that C++ does.

You have two options here:
1. Move the code for the two functions above main, so they are defined before main
OR:
2. Create two function prototypes for the functions before main
e.g.

float ctof(float d);
float ftoc(float f);

Also you appear to be missing an opening brace '{' after main() and according to the C++ standard, the signature of main should be int main() not void main()

Another thing:
Take note that the entire user input section of your code is wrong and will not do what you are hoping to do! For starters n is never initialised, or set to anything. So your switch statement will most likely only ever use the default case and the two values entered for f and c will never be used by the program.

For the user input section of your code, I'm guessing what you need to do is ask the user for a value, then ask whether they want to convert from celsius to farenheit, or farenheit to celcius. Or perhaps you need to ask them to enter the type of conversion they want to do and then ask for the value. But what you have at the moment does neither of those things! You need to go back to the drawing board and rethink your solution to the problem a little!

:edit:
Beaten to the punch by Banfa! :)

really this is great and u are right, I need to think on my solution before writing the programs...
I just solved it...I love u guys:)

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.