CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Oct 2015
    Posts
    4

    Lightbulb c++, code::Block

    1 #include <iostream>
    2 using namespace std;
    3 string getInitials(string firstname, string middlename, string lastname)
    4 {
    5 string first, middle, last;
    6 first=firstname.substr(0, 1);
    7 middle=middlename.substr(0, 1);
    8 last= lastname.substr(0, 1);
    9 return first+middle+last;
    10 }
    11 int main()
    12 {
    13 char choice;
    14 string firstName, middleName, lastName, getInitial;
    15 cout<<"Enter first name: ";
    16 getline(cin, firstName);
    17 cout<<"Enter middle name: ";
    18 getline(cin, middleName);
    19 cout<<"Enter last name: ";
    20 getline(cin, lastName);
    21 getInitial= getInitials(firstName, middleName, lastName);
    22 cout<<"Your initials are: " <<getInitial<<endl;
    23 cout<<"Want more name Initials Y/N: ";
    24 cin>>choice;
    25 while ((choice=='y')||(choice=='Y'))
    26 {
    27 cout<<"Enter first name: ";
    28 getline(cin, firstName);
    29 cout<<endl<<"Enter middle name: ";
    30 getline(cin, middleName);
    31 cout<<"Enter last name: ";
    32 getline(cin, lastName);
    33 getInitial= getInitials(firstName, middleName, lastName);
    34 cout<<"Your initials are: " <<getInitial<<endl;
    35 cout<<" Want more name Initials Y/N: ";
    36 cin >> choice;
    37 }
    38 return 0;
    39 }
    In the while loop of the above program line 28 is not executing and directly going to line 29. What to do so it can execute all the statements in the program.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured