且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从此程序中删除错误?

更新时间:2023-02-06 23:27:03

显然哟你不明白函数/子程序调用的基础知识。

建议:暂时忘记这个项目并正确学习C / C ++的工作原理。

找一对of tutos并完全跟随它们。

这里是语言作者对C和C ++参考书的链接。注意,C是C ++的祖先,所以知道C对C ++总是有用。

C编程语言 - ***,免费的百科全书 [ ^ ]

https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2。 pdf [ ^ ]

http://www.ime.usp。 br / ~pf / Kernighan-Ritchie / C-Programming-Ebook.pdf [ ^ ]



C ++编程语言 [ ^ ]

引用:

buti没有问我的老师



太糟糕了,解释你的工作原理是它的工作。 / blockquote>

你的情况:

这不是你进行函数调用的方式 - 这就是你声明它们的方式。



以上是您所述问题的答案。在线查看无数的例子如何完成(即,它几乎是任何C ++代码的一部分)。



或帮助,显示Turbo功能的使用C ++。



您将函数原型放在错误的位置。它们应该在任何其他函数之外声明:

  //  原型 
float 摄氏度( float , float float float int );
float Kelvin( float C, float K, float F, float ans, int y);
float Fahrenheit( float C, float K, float F, float ans, int y);

int main()
{
// 代码的其余部分就在这里。
}

***在原型中列出变量名称,并使用描述性名称变量因为大多数时候单个字母名称没用。


<pre>



<pre>#include<iostream.h>
#include<conio.h>
 float Celsius(float,float ,float , float ,int);
float Kelvin(float C,float K,float F,float ans,int y);                                     //prototypes
float Fahrenheit(float C,float K,float F,float ans,int y);
int main()
{

int x;
float answer;
cout<<"\t\t\tWElCOME TO TEMPERATURE CALCULATOR";
getch();
cout<<"\n\nSelect your first operator =>";
cout<<"\n1.Kelvin";
cout<<"\n2.Celsius";
cout<<"\n3.Fahrenheit\n\n";
cin>>x;
switch(x)
{
  case 1:float Kelvin(float C,float K,float F,float ans,int y) ;
			break;
  case 2:float Celsius(float C,float K,float F, float ans,int y)   ;
			break;
  case 3:float Fahrenheit(float C,float K,float F,float ans,int y)    ;
			break;
  }
 return 0 ;
  }                                                                                         //end of main
//------------------------------------------------------------------------------------------------------------------------------------------
float Kelvin(float C,float K,float F, float ans,int y)
{
cout<<"\nSelect your second operator =>";
cout<<"\n1.Celsius";
cout<<"\n2.Fahrenheit";
cin>>y;
switch(y)
 {case 1:cout<<"Enter Kelvin";
			cin>>K;
			C=K-273.15;
			ans=C;
			break;
  case 2:cout<<"Enter Kelvin" ;
			cin>>K;
			F=K*9/5-459.67;
			ans=F;
			break;
  }
  cout<<"your answer is "<<ans;
  return (0);
}


float Celsius(float C,float K,float F, float ans,int y)
{
cout<<"Select your second operator =>";
cout<<"\n1.Kelvin";
cout<<"\n2.Fahrenheit";
cin>>y;
switch(y)
 {case 1:cout<<"Enter Celsius";
			cin>>C;
			K=C+273.15;
			ans=K;
			break;
  case 2:cout<<"Enter Celsius" ;
			cin>>C;
			F=C*9/5+32;
			ans=F;
			break;
  }
  return ans;
}



float Fahrenheit(float C,float K,float F,float ans,int y)
{
cout<<"Select your second operator =>";
cout<<"\n1.Kelvin";
cout<<"\n2.Celsius";
cin>>y;
switch(y)
 {case 1:cout<<"Enter Fahrenheit";
			cin>>F;
			K=(F+459.67)*5/9;
			ans=K;
			break;
  case 2:cout<<"Enter Fahrenheit";
			cin>>F;
			C=(F-32)*5/9;
			ans=C;
			break;
  }
return ans;
}




the error is in 21st 23rd and 25th line inside the switch
in the function calls
i am compiling using turboc++ 4.5
i will copypaste the errorsbelow:
error FUNC.CPP 21:Expression syntax in function main()
error FUNC.CPP 23:Expression syntax in function main()
error FUNC.CPP 25:Expression syntax in function main()
i am trying to make a temperature converter using functions and some switches



What I have tried:

//i have tried changing the function calls with almost everything ie parameters and the definition just everything buti didnot ask my teacher although i tried looking into the book but that doesnt help trying to do this for ovr a week but i cant pls help .can somebody repair the code that will be really helpful


thanks in advance

Obviously you don't understand the basics of function/subroutine calling.
Advice: forget this project for now and learn properly how things works with C/C++.
Find a couple of tutos and follow them completely.
Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]

C++ Programing Language[^]
Quote:

buti didnot ask my teacher


Too bad, explaining you how things works is its job.


You cases:
That is just not the way you do function calls - it's how you declare them.

The above is the answer to your stated problem. Look up the uncountably many examples online of how this is done (i.e., it's part of almost any C++ code).

Or the help, showing usage of functions for Turbo C++.


You placed the function prototypes in the wrong place. They should be declared outside of any other functions :
//prototypes
float Celsius( float, float , float , float ,int );
float Kelvin( float C, float K, float F, float ans, int y );                                     
float Fahrenheit( float C, float K, float F, float ans, int y );

int main()
{
// rest of code goes here.
}

It is better to have variable names listed in the prototypes and use descriptive names for the variables because most of the time single letter names are not useful.