Is it possible to get a user to create new variables?

Apr 24, 2013 at 8:19pm
I am wondering.... let's say I execute my program and it runs perfectly. Is there a way to get the user to create new variables by writing their name and type of the black exe screen?

This is for my data base I am creating, and I was wondering if some one can create and initialize multiple sets of data arrays like for ex. User input (not in code it self but on screen) mark1 and a new array mark1 of constant size 10 is created.
Apr 24, 2013 at 11:11pm
bump
Apr 25, 2013 at 12:35am
Could you explain this a little bit more? I'm not really sure what you are asking for. As far as knowledge goes, you cannot do that. I'm not sure if you are asking to do this so someone can make an array to hold a set of values for that person can use it for whatever data he/she has.
Apr 25, 2013 at 1:36am
Yes you can.

e.g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>

using namespace std;

struct Book {
	string name;
	string cost;
};

int main() {
	cout << "Welcome to the book enterer :P " << endl;

	vector<Book> books;
	string choice = "y";
	string input = "";

	while (choice == "y") {
		Book new_book;

		cout << "Enter book " << books.size() + 1 << " name:";
		getline(cin, input);
		new_book.name = input;

		cout << "Enter book " << books.size() + 1 << " price:";
		getline(cin, input);
		new_book.cost = input;

		books.push_back(new_book);

		cout << "Would you like to enter another book? (y or n):";
		getline(cin, choice);
		while(choice != "y" && choice != "n") {
			cout << "Please try again (y or n):";
			getline(cin, choice);
		}
	}

	cout << endl << "You have entered " << books.size() << " books" << endl;
	for (unsigned i = 0; i < books.size(); ++i)
		cout << "Book[" << i << "]: " << books[i].name << " = " << books[i].cost << endl;

	cout << "Done" << endl;
	return 0;
}
Topic archived. No new replies allowed.