0

How do i show the number of declared arrays?

String list[9] Cout <<"enter first note" << endl; Cin >> list[0]; Cout << "Number of declared arrays is" <<

15th Feb 2019, 8:36 AM
Š›ŠµŠ½Š° Š“Š¾Š»Š¾Š²Š°Ń‡
Š›ŠµŠ½Š° Š“Š¾Š»Š¾Š²Š°Ń‡ - avatar
1 Answer
+ 4
#include <string> #include <iostream> int main() { std::string list[9]; int assigned {0}; // none were assigned // Repeat 9 times (number of array elements) for(int i {0}; i < 9; i++) { std::cout << "Enter note #" << (assigned + 1) << ": "; // Exit loop when input is invalid // or if there is no more input if(!(std::cin >> list[assigned])) break; // Display current string input std::cout << list[assigned] << std::endl; // Increment number of assigned elements assigned++; } // Display number of assigned elements std::cout << std::endl << assigned << " array elements populated\n"; return 0; } Please confirm if there is any problem reading the code, I am here to help. Hth, cmiiw
19th Feb 2019, 9:56 AM
Ipang