I was wondering if anyone could give me some help on this homework assignment. I have done all the tasks asks of me, but when I try to run the program to test it out, my IDE says the thread exits with a code 0 (whatever that means). I am almost sure I did everything correctly, I just need to be able to match it with the desired output. Here is the problem:

enter number 1: a 
That is an invalid number, enter another number: 10 
enter number 2: 20 
enter number 3: 30 
enter number 4; 40 
enter number 5: 50 
Table with the numbers in various bases 
bin        oct      dec     hex 
1010      012      10      A 
10100    024      20      14 
11110    036      30      1E
101000  050      40      28 
110010  062      50      32 
Table of formatted  and unformatted floating points 
unformatted formatted 
10          +1.00E+001
20          +2.00E+001
30          +3.00E+001
40          +4.00E+001
50          +5.00E+001


// bases.cpp
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
/* Include all necessary using statements from iostream */
using namespace std;
#include <iomanip>
/* Include all necessary using statements from iomanip */
#include <cmath>
/* Write a user-defined manipulator width8 that sets
   the width to 8 */
/* Write a user-defined manipulator width12 that sets
   the width to 12 */
ostream& width8(ostream& out)
{
    out.width(8);
    return out;
}

ostream& width12(ostream& out)
{
    out.width(12);
    return out;
}
// function to convert a decimal number to a binary number
int convertBinary( int x )
{
   double power;
   int result = 0;

   for ( power = 0; x >= pow( 2, power ); power++ ) ;
   for ( ; power >= 0; power-- ) {
      result *= 10;
      if ( x / pow( 2, power ) >= 1 ) {
         result++;
         x -= (int)pow( 2, power );
      }
   }
   return result;
}
void printTable( int a[], const int size )
{
   cout << "\nTable with the numbers in various bases\n";
    /* Write a statement to left justify the following table */
   /* Write a statement to print the header, use the width8
      manipulator for spacing */
   cout<<left;

   cout<< width12;

   for ( int i = 0; i < size; i++ )
      /* Write a statement to output the table of bases   */
   {
       cout<<a[i]<<endl;

      /* Octadecimal output should specify the base       */

       cout<<oct<<a[i]<<endl;


      /* Hexadecimal output should include only uppercase */

       cout<<hex<<uppercase<<a[i]<<endl;
   }
   cout << "\nTable of formatted and unformatted "
        << "floating points\n";
   /* Write a statement to print header, use the width12 
      manipulator for spacing */
   cout<<width12<<endl;
   for ( int j = 0; j < size; j++ ) {
      double x = static_cast< double > ( a[ j ] );
       /* Write a statement to output the formatted vs. 
         unformatted table */
      /* Formatted output should print in scientific notation,
         showing the decimal point and the sign, and
         have a precision of 2 */
      /* Undo formatting changes */
      {
          ios_base::fmtflags origFlags = cout.flags();
          cout<<a[j]<<endl;

          cout<<scientific<<dec<<showpos<<setprecision(2)<<a[j]<<endl;

          cout.flags(origFlags);
      }

}
}
int main()
{
   int x[ 5 ] = { 0 };
   for ( int counter = 0; counter < 5; counter++ ) {
      cout << "enter number " << counter + 1 << ": ";
      cin >> x[ counter ];
       /* Write a statement to test if stream errors occurred */
      /* If there were stream errors, input another number   */
      if (cin.fail())
      {
          //Clear error flag before next input
          cin.clear();
          //Input bad value the user typed
          char s[100];
          cin.getline(s, 100);

          //Output an error message and bad value
          cout<< "Bad integer: "<<s<<endl;

          //Input another integer
          cout << "enter number " << counter + 1 << ": ";
      cin >> x[ counter ];
      }

}
   printTable( x, 5 );
   return 0;
}

my IDE says the thread exits with a code 0

0 normally means the program ended with no errors, it ended normally.

What is your program not doing correctly?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.