Search This Blog

Simple c++ program shows how a program can use the formatted output statement

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
int no;
char name[30];
double fees;
cout<<"Enter your no:";
cin>>no;
cout<<"Enter your name:";
cin>>name;
cout<<"Enter the fees amount:";
cin>>fees;
cout.width(4);
cout.fill('0');
cout<<"The no is"<<no<<endl;
cout.fill(' ');
cout<<"The name is";
cout.setf(ios::left);
cout<<name<<endl;
cout.setf(ios::floatfield);
cout.precision(2);
cout<<"The fees is"<<fees<<endl;
}

Input:
Enter your no:3
Enter your name: Sridhar
Enter the fees amount:5640.3450

Output:
The no is 3
The name is Sridhar
The fees is 5640.35

No comments:

Post a Comment