Reputation: 37
I am learning C++ from the C primer. I am stuck on the last part of this question (1.6(p. 25))
Exercises Section 2.6.2 Exercise 2.41: Use your Sales_data class to rewrite the exercises in § 1.5.1 (p. 22), § 1.5.2 >(p. 24), and § 1.6 (p. 25). For now, you should define your Sales_data class in the same file >as your main function.
#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;
}
Where there are ** Xcode keeps telling me expected expression.. I have no clue what is wrong please help...
Upvotes: 0
Views: 516
Reputation: 5306
Adding to Shafik Yaghmours answer.
Some code I copied needed for me to retype the word float!
const float TEMPCOMP = ( 200 + (dT2 * (c6+100) >> 11) ) / 10;
I cant copy and paste to show how it looks..cause both lines (before and after) look the same when I past it here.
But in the editor(Arduino)...you can clearly see a difference. The f and l of float are touching!
Actually it was a Unicode Character 'LATIN SMALL LIGATURE FL' (U+FB02)
FileFormat.info
Upvotes: 0
Reputation: 158599
Based on your response to my comment you introduced some odd characters when you copied some code from the ebook. When I copied and compiled the program with gcc
I received errors like the following(live example here):
error: stray ‘\357’ in program
\357
is an octal escape sequence. When those characters are removed the program compiles fine.
Upvotes: 2