Mega Code Archive

 
Categories / C++ Tutorial / Array
 

Read array element one by one from keyboard

#include <iostream> #include <cctype> using std::cout; using std::cin; using std::endl; int main() {   int height[10];    int count = 0;     char reply = 0;    do {     cout << endl          << "Enter a height as an integral number of inches: ";     cin >> height[count++];     // Check if another input is required     cout << "Do you want to enter another (y or n)? ";     cin >> reply;   } while(count < 10 && std::tolower(reply) == 'y');    return 0; } Enter a height as an integral number of inches: 12 Do you want to enter another (y or n)? n