我正在制作购物清单计划。对于这个程序,我需要能够输入一个既接受数字(1564,121,1等)和单词(hello,goodbye等)组合的用户输入。该程序读取数字很好,但它不能处理单词。先感谢您。我坚持使用的代码部分如下:
int code, option, count = 0;
double quantity, price, cost;
string description;
cin >> code;
while ((code != 123456789) && (count < 2))
{
cout << "Incorrect code, try again \n";
cin >> code;
count++;
if (count == 2)
{
cout << "max # of tries reached. Goodbye. \n";
system("pause");
}
}
答案 0 :(得分:1)
您的(function (window) {
define(['knockout'], function (ko) {
/**
* Custom component to the given DOM node
* @type {{render: UIComponent.render}}
*/
var UIComponent = (function () {
return {
/**
* Render a component
* @param {object} component
* @param {object} element
*/
render: function (component, element, childComponents) {
var tagName = element.tagName && element.tagName.toLowerCase();
if (undefined !== childComponents) {
childComponents.forEach(function (child) {
ko.components.register(child.tagName, child.component);
});
}
ko.components.register(tagName, component);
ko.applyBindings(component, element);
},
/**
* Removes a component
* @param {object} component
* @param {object} element
*/
remove: function (component, element) {
ko.components.unregister(component.name);
ko.cleanNode(element);
// Remove any child elements from node
while (element.firstChild) {
element.removeChild(element.firstChild);
}
}
};
})();
window.UIComponent = UIComponent;
return UIComponent;
});
})(window);
变量现在是一个int。如果您希望将其作为字符串,请将其声明为:code
。请注意,您最初可能需要std::string code;
。另外,如果你想将它与数字进行比较,你可以调用#include <string>
(字符串有atoi()
)之类的东西,或者更好,你可以将它与“123456789”进行比较。 HTH。