Help

Sir what is the code for a program that input a name horizontal and display the name in vertical position using looping any kind of looping? PLSSS help IT IS MY ASS.
EX.
INPUT:Enter A name:John
OUTPUT:
J
O
H
N
Last edited on
If you will use class std::string to keep an entered name then the code can look the following way

for ( std::string::size_type i = 0; i < s.size(); i++ ) std::cout << s[i] << std::endl;

where s is declared as std::string s;

Or you can use the for statement based on range (if your compiler supports it )

for ( char c : s ) std::cout << c << std::endl;

or if you are using MS VC++

foreach( char c in s ) std::cout << c << std::endl;

Otherwise if you will use a character array then the code can look as

for ( const char *p = s; *p; ++p ) std::cout << *p << std::endl;

where s is declared something as char s[N];

EDIT: if you need to output each letter in upper case then you should apply function toupper from header <cctype>. For example

for ( char c : s ) std::cout << toupper( c ) << std::endl;

EDIT: The same can be done with standard algorithms. For example by means of std::transform
Last edited on
can you send me THE code plsss
You didn't really try. Here's some code, but this isn't a favor. If you can't get this sort of thing on your own, you will not (or at least should not) pass the class. Things will get much harder and if you don't take the time to learn it now, you will get so far behind and so frustrated when things start to get complicated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <string>
#include <iostream>
#include <cctype>

int main()
{
    std::string name;
    std::cout << "INPUT:Enter A name:";
    std::cin  >> name;
    
    std::cout << "OUTPUT:" << std::endl;
    
    for (std::string::size_type i = 0; i < s.size(); ++i)
        std::cout << toupper(name[i]) << std::endl;
    
    return 0;
}
Topic archived. No new replies allowed.