C++ examples for Language Basics:Console
The format of the cin is
cin >> value [>> values];
Prompt for a sales amount and print the sales tax.
#include <iostream> #include <iomanip> using namespace std; int main()//from ww w .ja va 2 s . c o m { float total_sale; // User's sale amount goes here. float stax; // Display a message for the user. cout << "What is the total amount of the sale? "; // Receive the sales amount from user. cin >> total_sale; // Calculate sales tax. stax = total_sale * .07; cout << "The sales tax for " << setprecision(2) << total_sale << " is " << setprecision (2) << stax; return 0; }