HELP! Printing out each characters of an array?

The Program will input a first and last name into one variable – using getline

Determine the length of the name and store the results in a variable.

Using a loop, print each of the characters of the name (array) on a separate line (from beginning of name list to end of name list).

This is what i got so far


1
2
3
4
5
6
7
8
9
10
int main() 
{ 
// Variable declarations: 
	string name;
	int namelength;

// Function body: 
	cout << "Enter your full name: " << endl;
	getline(cin, name);
	namelength = name.length();
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
#include "std_lib_facilities.h"

int main()
{
    string name;
    int name_length;

    cout << "Enter your full name: " << '\n';
    getline(cin, name);
    name_length = name.size();
    
    // using name length loop through each character of the string 'name' 
    // printing them out on their own line. 
    for(int i = 0; i < name.size(); i++)
        cout << name[i] << '\n';

    return 0;
}
Last edited on
Topic archived. No new replies allowed.