如何从此程序中删除错误? [英] How do I remove errors from this program?

查看:71
本文介绍了如何从此程序中删除错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre> 



< pre> #include < iostream.h >
#include < conio.h >
float 摄氏度( float , float float float int );
float Kelvin( float C, float K, float F, float ans, int y); // 原型
float 华氏度( float C, float K, float F, float ans, int y);
int main()
{

int X;
float answer;
cout<< \ t \\\\\\\\\到温度计算器 ;
getch();
cout<< \ n \ n选择您的第一个运营商=> ;
cout<< \ n1.Kelvin;
cout<< \ n2.2.Celsius;
cout<< \ n3.Fahrenheit\\\
\ n
;
cin>> x;
switch (x)
{
case 1 float 开尔文( float C, float K, float F, float ans, int y);
break ;
case 2 float 摄氏度( float C, float K, float F, float ans, int y);
break ;
case 3 float 华氏度( float C, float K, float F, float ans, int y);
break ;
}
return 0 ;
} // 主要结束
// -------------------------------- -------------------------------------------------- -------------------------------------------------- ------
float 开尔文( float C, float K, float F, float ans,< span class =code-keyword> int y)
{
cout<< \ n选择你的第二个算子=>;
cout<< \ n1.Celsius;
cout<< \ n2.Fahrenheit;
cin>> y;
switch (y)
{ case 1 :cout<< 输入Kelvin;
cin>> K;
C = K- 273 15 ;
ans = C;
break ;
case 2 :cout<< 输入Kelvin;
cin>> K;
F = K * 9 / 5- 459 67 ;
ans = F;
break ;
}
cout<< 你的回答是<<答;
return 0 );
}


float 摄氏度( float C , float K, float F, float ans, int y)
{
cout<< 选择第二个运算符=>;
cout<< \ n1.Kelvin;
cout<< \ n2.Fahrenheit;
cin>> y;
switch (y)
{ case 1 :cout<< 输入摄氏度;
cin>> C;
K = C + 273。 15 ;
ans = K;
break ;
case 2 :cout<< 输入摄氏度;
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<< 选择第二个运算符=>;
cout<< \ n1.Kelvin;
cout<< \ n2.2.Celsius;
cin>> y;
switch (y)
{ case 1 :cout<< 输入Fahrenheit;
cin>> F;
K =(F + 459。 67 )* 5/9;
ans = K;
break ;
case 2 :cout<< 输入Fahrenheit;
cin>> F;
C =(F- 32 )* 5/9;
ans = C;
break ;
}
return ans;
}







错误发生在21日23日函数中的开关
内部的第25行调用
i使用turboc ++编译bi
i将copypaste错误如下:
error FUNC.CPP 21:函数main中的表达式语法()
错误FUNC.CPP 23:函数main()中的表达式语法
错误FUNC.CPP 25:函数main()中的表达式语法
i我试图使用函数和一些开关来制作温度转换器





我尝试过:



//我已经尝试用几乎所有的东西来改变函数调用,即参数和定义只是所有buti都没有问我的老师虽然我试着查看这本书,但这并没有帮助尝试为ovr一周这样做但我不能帮助.can有人修复了真正有用的代码





提前感谢

解决方案

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

建议:暂时忘记这个项目并正确学习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.


这篇关于如何从此程序中删除错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆