|
From: Kirktoun .....T. C. F. <kir...@bt...> - 2002-03-31 13:16:15
|
Hello there,=20
The following code based on yours outputs the five floats, column width =
can be any integer number you want. I also initialised the variables, =
one of the reasons you had no output was that you did not tell the print =
statement to output the variable number1 etc. although i think an =
earlier correspondent noticed this. The numbers line up ok, although the =
text"number1" and the actual value of the variable number1 are on =
different lines, there are ways round this but not without changing the =
code considerably. You would be better off looping this program anyway =
both for input and output.
#include <iostream>
#include <iomanip>
#include <conio.h>
using std::cout;
using std::cin;
using std::endl;
float number;
int main()
{
float number1=3D0, number2=3D0, number3=3D0, number4=3D0, number5=3D0;
cout << " Enter 5 floating point numbers " << endl;
cin >> number1 ;
cin >> number2 ;
cin >> number3 ;
cin >> number4 ;
cin >> number5 ;
cout << " The floating point numbers you entered are " << endl;
cout << " number 1 is " <<endl;
cout.width(30);
cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint)<< =
number1 <<endl;
cout << " number 2 is " <<endl;
cout.width(30);
cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint)<< =
number2 <<endl;
cout << " number 3 is "<<endl;
cout.width(30);
cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint)<< =
number3 <<endl;
cout << " number 4 is "<<endl;
cout.width(30);
cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint)<< =
number4 <<endl;
cout << " number 5 is "<<endl;
cout.width(30);
cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint)<< =
number5 <<endl;
cout << "Here are the five floats you wanted" <<endl;
cout <<endl <<endl <<endl;
cout << "Strike any key to exit program" <<endl;
getche();
return 0;
}
=20
|