我正在从C入门学习C ++。我被困在这个问题的最后部分(1.6(p。25))
练习第2.6.2节练习2.41:使用Sales_data类重写§1.5.1(p。22),§1.5.2>(p。24)和§1.6(p。25)中的练习。现在,您应该在与主要功能相同的文件中定义Sales_data类。
#include <iostream>
#include <string>
struct Sales_data
{
std::string Book_Name;
unsigned Units_Sold = 0;
double Revenue = 0.0;
};
int main()
{
double price;
Sales_data total; // variable to hold data for the next transaction // read the first transaction and ensure that there are data to process
if (std::cin >> total.Book_Name >> total.Units_Sold >> price)
{
total.Revenue = total.Units_Sold * price;
Sales_data trans; // variable to hold the running sum // read and process the remaining transactions
while (std::cin >> trans.Book_Name >> trans.Units_Sold >> price)
{
trans.Revenue = trans.Units_Sold*price;
// if we're still processing the same book
if (total.Book_Name == trans.Book_Name)
{
total.Units_Sold += trans.Units_Sold; // update the running
total.Revenue += trans.Revenue; // update the running
}
else
{
std::cout << total.Book_Name << total.Units_Sold << total.Revenue;
**total.Book_Name = trans.Book_Name;**
total.Units_Sold = trans.Units_Sold;
**total.Revenue = trans.Revenue;**
}
**std::cout << total.Book_Name << total.Units_Sold << price << std::endl;** //print the last transaction
}
}
else
{
// no input! warn the user
std::cerr << "No data?!" << std::endl;
return -1; // indicate failure
}
return 0;
}
哪里有** Xcode总是告诉我期望的表达式。我不知道出什么问题了,请帮助...
gcc
复制并编译程序时,收到如下错误(error: stray ‘\357’ in program
\357
是八进制转义序列。除去这些字符后,程序可以正常编译。
我复制的一些代码需要我重新输入单词[[float!]!
const燕麦TEMPCOMP =(200 +(dT2 *(c6 + 100)>> 11))/ 10;
我无法复制和粘贴以显示外观。.造成两行(前后)当我在此处粘贴时,外观看起来相同。但是在编辑器(Arduino)中,您可以清楚地看到区别。浮子的f和l接触!
实际上是Unicode字符“拉丁文小写本FL”(U + FB02)FileFormat.info