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" <<
1 Resposta
+ 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