A street vendor sells three types of juice: apple, grape, and orange. They all sell for $2.49. Ask the vendor how much of each were sold today and then calculate the sales ($) for each. Format your output as shown below, making sure Sales numbers have exactly two decimal places and that all widths / alignments match mine.
Output:
How much apple juice did you sell today? [assume user inputs 5]
How much grape juice did you sell today? [assume user inputs 8]
How much orange juice did you sell today? [assume user inputs 10]
FRUIT QTY SALES($)
Apple 5 12.45
Grape 8 19.92
Orange 10 24.90
-------------------------
1234567890123456789012345 <-- DO NOT output this area. It is here to help you align things.
#include <iostream>
#include <iomanip>
int query(const std::string& juice){
int amount;
std::cout << "How much " << juice << " did you sell today?\n";
std::cin >> amount;
return amount;
}
int main() {
int apple, grape, orange;
apple = query("apple");
grape = query("grape");
orange = query("orange");
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::cout << "FRUIT QTY SALES($)\n";
std::cout << "Apple " << apple <<" " << apple*2.49 << std::endl;
std::cout << "Grape " << grape <<" " << grape*2.49 << std::endl;
std::cout << "Orange " << orange <<" " << orange*2.49 << std::endl;
std::cout << "-------------------------";
return 0;
}
Comments
Leave a comment