Answer to Question #344309 in C++ for Rille

Question #344309

Create a c++ program that asks the user to input the full name 10 times using for, do while and while loop. Then display.

1
Expert's answer
2022-05-24T13:54:24-0400
#include <iostream>
#include <string>
using namespace std;

int main() {
    string name[10];
    int i;
    cout << "Input the full name 10 times: " << endl;
//1.  for. storing information
    for( i = 0; i < 10; ++i)    {
        cout<< i+1 <<". ";
        getline(cin, name[i]);
        }
// display information
    cout<<endl<<"Names: "<<endl;    
     for( i = 0; i < 10; ++i)    
        cout<< name[i]<<endl;
        
//2. do while. storing information
    cout << "Input the full name 10 times: " << endl;
    i=0;
    do{
        cout<< i+1 <<". ";
        getline(cin, name[i]);
        i++;
    }   while (i<10);
// display information
    i=0;
    cout<<endl<<"Names: "<<endl;    
     do{
        cout<< name[i]<<endl;
        i++;
    }   while (i<10);
                
//3. while. storing information
    cout << "Input the full name 10 times: " << endl;
    i=0;
    while(i<10){
        cout<< i+1 <<". ";
        getline(cin, name[i]);
        i++;
    }  
    // display information
    i=0;
    cout<<endl<<"Names: "<<endl;    
    while(i<10){
        cout<< name[i]<<endl;
        i++;
    }              
   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS