而循环不工作终止问题
While Loop not Working termination issue
所以基本上用户输入木材类型可以是P F C M O 如果用户输入"T",循环应该终止并输出我到目前为止拥有的代码总数,但它不起作用。在 cout 中,我没有编写代码来输出总数,但它只是一个测试,看看我是否得到输出,我在 void 函数中我从用户那里获得输入,例如可能是 P 10 10 10 10 如果它只是 T 循环应该终止并 cout 我曾经拥有的东西。
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void get_user_input(char&, int&, int&, int&, int&);
float compute_item_cost(char, int, int, int, int);
const float pine_cost = 0.89;
const float fir_cost = 1.09;
const float cedar_cost = 2.26;
const float maple_cost = 4.50;
const float oak_cost = 3.10;
int main()
{
int quanity, height, width, length;
string name_of_wood;
char type;//declare variables
get_user_input(type, quanity, height, width, length);
do
{
get_user_input(type, quanity, height, width, length);
} while (type!='T');
cout << "33333333333333333333333333333333333e";
return 0;
}
void get_user_input(char& type, int& quanity, int& height, int& width, int& length)
{
cout << "Enter the wood type";
cin >> type >> quanity >> height >> width >> length;
}
试试这个:
void get_user_input(char& type, int& quanity, int& height, int& width, int& length)
{
cin >> type;
if (type == 'T') return;
cin >> quanity >> height >> width >> length;
}
它不起作用的原因是因为它在 cin 语句完成之前等待您输入所有五个值。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 在抛出 'std::invalid_argument' 的实例后终止调用 what(): stoi (找不到问题所在)
- C++程序问题:抛出'std::invalid_argument'实例后终止调用
- 可变参数模板中递归模板函数的终止问题
- (C++) 学习向量 - 编码/输入流终止/比较向量的问题
- 而循环不工作终止问题
- 而循环终止问题
- 这段代码出了什么问题?它在第二个 cin 可以执行之前终止
- CPP-Netlib 问题,在抛出 'boost::exception_detail::clone_impl 的实例后调用终止
- 通过 -1 终止时出现问题
- 这个程序有什么问题,它终止了?
- 和野兔模拟终止问题
- 程序在输入开尔文或摄氏后终止?(我的代码有什么问题?
- 如果应用程序存在内存泄漏,是否在终止时解决这些问题