繁体   English   中英

我将如何安排具有定值价值的多种电影?

[英]How would I arrange for multiple cin with a sentinal value?

该程序应从另一个文件中获取数据。 该文件的编号如下:

2017年3月12日

4223

161 10.0 0 2吨

99 5.00 10 3吨

0

581

123 45.00 10 3吨

921 5.25 0 1牛

83 14.99 25 2吨

0

收据编号为4223和581; 161、99、123等是商品ID; 在项目ID之后还有其他四个输入,我将在以后处理。 0为前哨。

我尝试的是使用while循环读取数据,如果不是哨兵,则至少要处理和输出项目ID。 但是,它不起作用。

#include <iostream>
using namespace std;

int main()
{
  double operation;
  int year; 
  int month;
  int day; 
  int receiptnum
  int itemid;
  double regprice; 
  int percentoff;  
  int numpurchased;
  char taxstatus; 

  cin >> year >> month >> day;
  cout << "Date of purchases: "  << month << "/" << day << "/" << year     << endl

  cin >> receiptnum >> itemid >> regprice >> percentoff >> numpurchased >> taxstatus;
  while(receiptnum && itemid && regprice && percentoff && numpurchased && taxstatus != '0')
  {
    //    cin >> itemid >> regprice >> percentoff >> numpurchased >> taxstatus;
    cout<< itemid << endl;
  }


 return 0;
}

您使用的逻辑运算符错误。 您必须分别将它们分别比较为0,并在比较结果上使用&&运算符。

while(thing1 != 0 && thing2 != 0)

&&运算符唯一要做的就是获取两个布尔值,如果两个操作数都为true,则返回true。 它无法执行将变量与多个值进行比较或将多个值与同一个变量进行比较的操作。

另外,变量例如recipenum代表数字,而不是字符。 因此,您应该将它们与0而不是代表字符0'0' (而不是数字值)进行比较。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM