0

hi, I need help in adding questions in a program using strings, structures or array.............
Plz help me n snd the code

4
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by Clinton Portis
0

Need a lot more detail. You may get a response if you:
1) Post your exact problem.
2) Show some effort in trying to solve your problem.

0

i think i know what he wants, here is some example code i came up with :)

#include <iostream>

using namespace std;

struct SInfo {
    string name[100];
};

SInfo info;

int main() {
    cout << "First name: ";
    std::cin >> info.name[0];
    cout << "Last name: ";
    std::cin >> info.name[1];
    cout << "Your name is: " << info.name[0] << " " << info.name[1] << endl;

    return(0);
}
0

One slight adjustment to your code will allow the user to add many names:

#include <iostream>

struct SInfo {
    string name[100];
};

int main() 
{
    SInfo info[20];
    char again = '\0';
    int counter = 0;
 
    do{
             cout << "First name: ";
             std::cin >> info[counter].name;
             cout << "\nWould you like to enter another name?  (Y/N) ";
             std::cin >> again;
             counter++;
     }while(again == 'y' || again == 'Y');

     std::cout << "\nHere is the list of names: \n\n";

     for(int i=0; i<counter; i++)
     {
             std::cout << info[i].name << endl;
     }

     return 0;
}

Edited by Clinton Portis: dark magic.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.