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

Recommended Answers

All 4 Replies

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.

Member Avatar for stephen.id

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);
}

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.