参数太多,无法正常工作 我目前正在为我的计算机科学课程做作业,我是一个C++新手。然而,当我编译程序时,它说它有太多的参数来实现“void results”

参数太多,无法正常工作 我目前正在为我的计算机科学课程做作业,我是一个C++新手。然而,当我编译程序时,它说它有太多的参数来实现“void results”,c++,computer-science,C++,Computer Science,有人能解释一下我如何解决这个问题吗。您的时间将不胜感激 以下是作业的说明 我需要创建一个程序,实现将温度从一个刻度转换为另一个刻度对应值的功能。 使用F表示华氏温度,C表示摄氏温度,以下公式用于在两个温标之间进行转换 F=1.8C+32 C=F-32/1.8 程序必须提示用户输入初始温度的刻度和度数,并显示所提供温度的华氏度和摄氏度,四舍五入到小数点后两位。如果为刻度或温度提供了不适当的输入,程序必须显示适当的错误消息,并在不显示任何结果的情况下终止执行。温度标度的适当输入取决于信息的获取方式;

有人能解释一下我如何解决这个问题吗。您的时间将不胜感激

以下是作业的说明

我需要创建一个程序,实现将温度从一个刻度转换为另一个刻度对应值的功能。 使用F表示华氏温度,C表示摄氏温度,以下公式用于在两个温标之间进行转换

F=1.8C+32 C=F-32/1.8

程序必须提示用户输入初始温度的刻度和度数,并显示所提供温度的华氏度和摄氏度,四舍五入到小数点后两位。如果为刻度或温度提供了不适当的输入,程序必须显示适当的错误消息,并在不显示任何结果的情况下终止执行。温度标度的适当输入取决于信息的获取方式;适当温度是大于或等于绝对零度的任何值,即-459.67 F或-273.15 C

程序的主函数只能包含变量声明和函数调用。要处理数据,您的程序至少必须为以下每项任务正确使用适当的功能,尽管您可以根据需要包括尽可能多的附加功能:

1.显示向用户解释程序的简要概述和/或说明集

2.让用户输入使用的温标

3.让用户输入初始温度读数

4.将华氏温度转换为摄氏温度

5.将摄氏温度转换为华氏温度

6.显示结果

#include <iostream>
#include <iomanip>
#include <string>


using namespace std;

// Prototype
void overView();
void results();
char tempScale();
float tempReading();
float convertFtoC(float);
float convertCtoF(float);

int main(){


    overView ();
    cout << setprecision (2) << fixed;

    float degree = tempReading();
    char scale = tempScale();
    float fahrenheit, celsius;

    if(scale == 'F'){
          celsius = convertFtoC(degree);
          fahrenheit = degree;

    }
    else if (scale == 'C'){
          fahrenheit = convertCtoF(degree);
          celsius = degree;
    }
    else{
        cout << "***Error: Invalid temperature Scale Please try again!" << endl;
        return 0;
    }

    results(fahrenheit, celsius);

   return 0;

}

// this function was build to give an overview to the user explaining the program
void overView(){
    cout << "This program will convert a temperature reading provided in" << endl;
    cout << "either Fahrenheit or Celsius to the other measurement scale." << endl;
    cout << "------------------------------------------------------------" << endl;
    cout << endl;
}

// this function was build to ask the user to chose the temperature scale
char tempScale(){
    char scale;
    cout << "Please chose the temperature scale that you wish to use (F = Fahrenheit; C = Celsius): ";
    cin >> scale;
    return scale;
}

// this function was build to ask the user to enter the temperature reading in degree
float tempReading(){
    float degree;
    cout << "Please enter your temperature reading (in degrees): ";
    cin >> degree;
    return degree;
}

// This function was build to converts a Fahrenheit temperature to celsius
float convertFtoC(float fahrenheit){
    float celsius;
    celsius = (fahrenheit - 32) / 1.8;
    return celsius;
}

// This function was build to converts a Celsius temperature to Fahrenheit
float convertCtoF(float celsius){

    float fahrenheit;
    fahrenheit = 1.8 * (celsius + 32);
    return fahrenheit;

}

// This function will display the results to the user
void results(float fahrenheit, float celsius){

cout <<"Your temperature reading converts as follows:" << endl;
cout << "Fahrenheit: " << fahrenheit << endl;
cout << "Celsius: " << celsius << endl;

}

你的原型没有参数,所以C++认为你做的是错误的,它没有输入。 更改:

// Prototype
void overView();
void results();


应该修好它!C++比你的实现更重视你的原型。这也发生在C中。

在您的前向函数声明更改无效结果中;若要作废resultsfloat,请选择float;。错误基本上是说你定义了一个没有参数的函数,但是你用两个参数调用它。

C++倾向于比你的实现更认真地对待你的原型,你的意思是什么更认真?声明和定义中的函数签名必须完全匹配,仅此而已。这就是我的意思。如果让它选择使原型出错或函数调用出错,它将始终选择函数调用。这就是我说的更严肃的意思,但我可以看出这是多么误导。
// Prototype
void overView();
void results(float fahrenheit, float celsius);