指定时功能不会重复

Function does not repeat when specified

本文关键字:定时 功能      更新时间:2023-10-16

我做了一个函数" 1",我想问用户"您想重复功能" 1"?",我在做什么错?这是我的代码:

#include <cstdlib>
#include <iostream>
using namespace std;
void temperature()
{
    float c,f;
    cout<<"Áveskite temperatørà pagal Celsijø: ";
    cin>>c;
    f=(c*1.8)+32;
    cout<<"Temperatûra pagal Farenheità: ";
    printf("%2.2f", f);
    cout<<endl;
}

int main()
{
    setlocale(LC_ALL,"Lithuanian");
    temperature();
    char isjungti;
    cout<<"Paversti dar vienà temperatûrà?(T)";
    cin>>isjungti;
    if(isjungti == 'T' || 't')
     {
     return temperature(); //I get an error here.              
     }
    system("PAUSE");
    return EXIT_SUCCESS;
}

感谢您的帮助。

return将退出函数范围。使用

之类的东西
while (isjungti == 'T' || isjungti == 't') {
    temperature()
}

或类似。

isjungti == 'T' || 't'肯定是错误的。另外,return temperature();,因为temperature()返回void

您可能的意思是:

 if(isjungti == 'T' || isjungti == 't')
 {
    temperature(); //I get an error here.              
 }

main()是int,您的函数不会返回任何内容。从错误的行中剥离"返回"只是为了调用函数并在返回值上读取。