Tech Blog   »   Home   »   Coders Forum   »   Computer Directory   »   Math Calculators   »   RSS:Directory|Forum 



// =======================================================================

// Arrays with initializations {}.

// const int SIZE = 4; declare a const int size for arrays.

// ======================================================================

#include <iostream>

#include <string>

using namespace std;

int main()

{

       const int SIZE = 4; // Declare a const int size for arrays.

 

       double scores[SIZE] = {1.5, 2.5, 3.5}; // To initialize to zero put {0}.

       string names[SIZE] = {"John Jones", "Fred Halo", "Mike Stern", "Joe Swindle"};

 

       // Output the results from double scores array.

       cout << "Here are the values:\n\n";

       cout << scores[0] << '\t' << scores[1] << '\t'

            << scores[2] << '\t' << scores[3] << endl << endl;

 

       // Output the results from the the string names array.

       cout << "Here are the names:\n\n";

       cout << names[0] << endl << names[1] << endl

            << names[2] << endl << names[3] << endl << endl;

 

       return 0;

}

/* =================== output ==============================================

Here are the values:

 

1.5     2.5     3.5     0

 

Here are the names:

 

John Jones

Fred Halo

Mike Stern

Joe Swindle

 

Press any key to continue . . .

*/// =======================================================================

 

Validated with no errors:

Valid XHTML 1.0 Transitional     Valid CSS!


Site Map