在c++中设置最大值
Setting a max number in c++
可能是一个简单的答案,但这已经困扰了我一段时间了。我似乎在设置最大值时遇到了问题。例如,我向用户询问本月使用的小时数,最大小时数不能超过744。我该如何设置这个最大值?提前感谢您的帮助。
使用if语句:
if (hours < max_hours) {
// Do stuff
}
else {
std::cout << "Invalid Hours";
}
int main() {
int workhours;
std::cout << "Please enter your workhours: ";
std::cin >> workhours;
if (workhours < max_hours) {
//good, do your stuff
else {
std::cout << "Invalid Working Hours";
std::cout << "Please enter your real workhours: ";
std::cin >> workhours;
}}
}
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 使用指针从C++中的数组中获取最大值
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 如何创建一个函数来计算并返回平均值、最大值和最小值
- 在二维数组中查找最小值和最大值?
- 整数溢出,最大值为 pow(10,19)
- 以C++递归方式查找向量中的最大值
- C++ - 如何在结构向量中找到结构体一个成员的最大值?
- 查找数组中第一个最小值和最后一个最大值元素之间的算术平均值
- C++ 函数,用于查找传入的 N 个数字的平均值、总和、最小值和最大值
- 我的 If Else 语句无法在向量 (C++) 中提供最大值
- 如何使用可变参数模板类使用模板元编程获得最大值
- C++不同的最小最大值实现
- 查找不在标准中的第一个值::设置<int>最小-最大值
- 如何在一定范围内将无锁更新索引设置为最大值
- 当输入高于最大值的值时,如何将 QSpinBox 的值设置为 max
- 在c++中设置最大值
- 如何在C++中将 const int 设置为最大值
- 在c++srand中设置随机数的最大值和最小值
- 设置Complex Double的最大值来代替Infinity