C 中的空隙函数误差
Void function error in c++
,因此我使用了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;
}
相关文章:
- C++17中不定参数函数的误差
- 犰狳函数的不同最小二乘误差
- variadic函数和折叠表达:试图在Visual Studio 2017中编译时致命误差
- C lambda函数转换误差
- 用struct初始化C 向量时的构造函数误差
- C 类函数链拨打编译误差
- C 中的空隙函数误差
- 控制可能达到C 中非空隙函数误差的末端
- C 中带有读取函数的编译误差
- Aruco函数估计posesinglemarkers()误差
- 带有模板构造函数的预期未合格的ID误差
- 需要说明简单的C 程序中的编译误差,以演示超载函数
- 传递variadic arg to模板函数时的汇编误差
- 功能原型误差,非空隙函数
- cmath精度误差中的楼层函数
- 在没有CRT,Memcpy和Memset固有函数的情况下链接误差
- c++中的虚误差函数
- 在C++中使用地板函数的舍入误差
- 循环函数给出"return’ with a value, in function returning void"误差
- 非常简单的优化算法产生一个函数参数误差