Get to know the cin Operator, read float value - C++ Language Basics

C++ examples for Language Basics:Console

Introduction

The format of the cin is

cin >> value [>> values];

Prompt for a sales amount and print the sales tax.

Demo Code


#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;
}

Result


Related Tutorials