#include <std_lib_facilities.h> #include <clocale> double trans(); int main() { setlocale(LC_CTYPE, "rus"); double x=' ',z=' ',r=' '; char unit ='a'; while (cin>>x>>unit) { trans(x, unit); if (x<z) { z=x; cout <<"Наименьшее среди введенных\n"; } else if (x>r) { r=x; cout <<"Наибольшее среди введенных\n"; } } return 0; } double trans(double x,char unit) { switch (unit) { case 'cm': unit ='m'; x = x/100; break; case 'in': unit ='m'; x = x/254; break; case 'ft': unit ='m'; x = x/3048; break; case 'm': x = x; break; default: cout <<"Неизвестное значение\n"; break; } return x,unit; } 2 answers
An error message means that you first declared the trans function as having no parameters
double trans(); However, then in the body of the main function you call it with two arguments
trans(x, unit); You have a trans function declaration before the main function does not match the definition of the same function that follows main .
Nevertheless, even if you correct this error, your program contains other errors and does not make sense.
For example, this variable initialization
double x=' ',z=' ',r=' '; meaningless. The values of these variables will contain the value of the space character code, which, for example, is 32 in the ASCII table.
Further, in case labels you use multibyte character literals
case 'cm': They are of type int while only one byte can be stored in a unit object of type char . Therefore, no comparison will be made.
Also, as I understand it, you should output the largest and smallest values after the loop, and not at each iteration of the loop.
If I understood the task correctly, the program may look like this (you can also include your headers in the program)
The program uses objects of the std::pair and std::string classes. It makes writing a program easier.
#include <iostream> #include <string> #include <utility> std::pair<double, std::string> trans( const std::pair<double, std::string> & ); int main() { std::pair<double, std::string> value; std::pair<double, std::string> min( 0.0, "m" ); std::pair<double, std::string> max( 0.0, "m" ); bool empty_sequence = true; while ( std::cin >> value.first >> value.second ) { std::pair<double, std::string> tmp = trans( value ); if ( tmp.second != "undefined" ) { if ( empty_sequence || tmp.first < min.first ) { min = value; } if ( empty_sequence || max.first < tmp.first ) { max = value; } } empty_sequence = false; } if ( !empty_sequence ) { std::cout <<"Наименьшее среди введенных: " << min.first << min.second << std::endl; std::cout <<"Наибольшее среди введенных: " << max.first << max.second << std::endl; } return 0; } std::pair<double, std::string> trans( const std::pair<double, std::string> &value ) { std::pair<double, std::string> tmp( 0.0, "m" ); if ( value.second == "cm" ) { tmp.first = value.first / 100.0; } else if ( value.second == "in" ) { tmp.first = value.first / 254.0; } else if ( value.second == "ft" ) { tmp.first = value.first / 3048.0; } else if ( value.second == "m" ) { tmp.first = value.first; } else { tmp.second = "undefined"; } return tmp; } If you enter, for example, the following values
1 m 120 cm 450 ft 1200 in then the resulting console output will be
Наименьшее среди введенных: 1200in Наибольшее среди введенных: 120cm You announced
double trans(); trans as a function without parameters . And then you pass something into it ... Here is the compiler and swears.
Announce what it actually is:
double trans(double, char); - Thank. It all worked! - Ksand