Advertisement
Guest User

double numbers in columns of same width

a guest
Feb 26th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <sstream>
  5.  
  6.  double string_to_double( const std::string& s )
  7.  {
  8.    std::istringstream i(s);
  9.    double x;
  10.    if (!(i >> x))
  11.      return 0;
  12.    return x;
  13.  }
  14. using namespace std;
  15.  
  16. int main()
  17. {
  18.     double TAB[1000];
  19.     int max_length=0;
  20.     int liczba=0;
  21.     string liczby;
  22.     cout << "How many numbers are you inputting into array: ";
  23.     cin >> liczba;
  24.     for (int a=0; a<=liczba; a++)
  25.     {
  26.         cin >> liczby;
  27.         if (liczby.length() > max_length){max_length=liczby.length();}
  28.         TAB[a]=string_to_double (liczby);
  29.     }
  30.     cout << endl;
  31.    
  32.     for (int a=0; a<=liczba; a++)
  33.     {
  34.        
  35.     }
  36.     for (int a=0; a<=liczba; a++)
  37.     {
  38.         cout << setw(max_length) << TAB[a] << endl;
  39.     }
  40.     cin.get();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement