C 中的空隙函数误差

Void function error in c++

本文关键字:函数 误差      更新时间:2023-10-16

,因此我使用了void函数并在其中放置了5个参数;1.提示用户输入2.价值。

我对此功能没有很好的了解,但这是我到目前为止的。

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include<limits>
using namespace std;
// function declaration
void get_data(string, string, int&, int, int);

int main() 
{
int year;
string input_prompt;
string range_prompt;
get_data(input_prompt, range_prompt, year, 1970, 2020);
cout << "nYour inputs are:n";
cout << "..." << year  << "n";
int month;
string input_prompt;
string range_prompt;
get_data(input_prompt, range_prompt, month, 1, 12);
cout << "..." << month << "n";
....
return 0;
}
// function definition 
void get_data(string input_prompt, string range_prompt, int& input, int 
criteria_1, int criteria_2){
input_prompt = "Please enter the year: ";
range_prompt = "Invalid input. 1970 <= year <= 2020!";
criteria_1 = 1970;
criteria_2 = 2020;
.....

}

每次尝试运行此操作时,我都会收到一条错误消息。我知道这是因为void函数中的值不断变化,并且在主函数中没有提到这些值...或类似的内容。我怎样才能解决这个问题?

更新:

我的意思是,空隙功能用于在指定范围内从用户那里收集年,月,每日,小时,最小和第二个。

主函数将在void函数中显示数据的集合。

输出应为:

Please enter the year: 2013  
Please enter the month: 1  
Please enter the day: 24  
Please enter the hour: 13  
Please enter the minute: 55  
Please enter the second: 45  
Your inputs are:  
Year = 2013  
Month = 1  
Day = 24  
Hour = 13  
Minute = 55  
Second = 45   

我可以从用户那里获得输入。现在,我需要收集所有这些输入并将其显示在屏幕上。那是我做错了什么的一部分,但我不知道。

#include <iostream>
using namespace std;
/*Acode for swaping two values using void function*/
int z=0, x, y;
void func(int& x, int& y){
   cout<<"Enter the value of x: ";
   cin>>x;
   cout<<"Enter the value of y: ";
   cin>>y;
   z=x;
   x=y;
   y=z;
}
int main()
{
   func(x,y);
   cout<<"The value of x after swaping is: "<<x<<endl;
   cout<<"The value of y after swaping is: "<<y<<endl;
   return 0;
}