Checkpoint 9.2.1.
Which of the following would be a correct way to display the price of an object and finish the
printPrice
, which we saw on the previous page?
struct Price {
int dollar, cents;
};
void printPrice(Price& p) {
// Implementation here
}
int main() {
Price sandwich = { 3, 45 };
Price coffee = { 2, 50 };
Price pastry = { 2, 0 };
}
cout << "Price is " << "p.dollar" << " dollars and" << "p.cents" << "cents." << endl;
- Try again. We want to print the values rather than statements.
cout << "Price is " << p.dollar << " dollars and " << p.cents << " cents." << endl;
- Correct!
cout << "Price is " << p.dollar << " dollars and " << p.cents << " cents." << endl
- This would not compile. There is an important character that ends nearly all statements in C++.