Write a C++ program where the user input his/her first name into an array of characters. Then display the name (from the array) one letter on each line. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a C++ program where the user input his/her first name into an array of characters. Then display the name (from the array) one letter on each line.

8th Sep 2016, 12:36 PM
Najwa
Najwa - avatar
3 Answers
+ 5
#include <iostream> #include <string> using namespace std; int main() { string name; cout << "Enter your name: "; getline(cin, name); for (int i = 0; i < name.length(); i++) cout << name.at(i) << "\n"; } Same thing, but without a 10 character limit.
8th Sep 2016, 8:36 PM
Cohen Creber
Cohen Creber - avatar
+ 2
#include <iostream> using namespace std; int main() { char myName[10]; cout << "Please enter your name: "; cin >> myName; cout << endl; for (int i = 0; i <= 9; i++) { cout << myName[i] << endl; } return 0; }
8th Sep 2016, 5:33 PM
Davood Abdollahi
Davood Abdollahi - avatar
- 1
part2: Next display the name in the fashion of the example below. You must use for loop(s)
8th Sep 2016, 12:37 PM
Najwa
Najwa - avatar