Thank you so much for your help!
xismn: Your code does almost exactly what I need it to, except that I was just using A, B, C as examples. They need to be full words. When I try to substitute A for Apple (for example). It's telling me that there are too many characters in the constant.
I only barely understand char, but is it possible to substitute the letters with strings somehow? I've been messing with it, but without success. Creating a string first and then inserting into the array does not seem to work.
The idea is that users can rate certain items (for the sake of continuity, lets say apples).
So we have Macintosh, Gala, Golden Delicious, Granny Smith, etc...
Each of them need to be rated on a scale of 0-6.
Eventually, I want to be able to compare two (or more) users' input. User 1 rates 200 types of apples, User 2 rates 200 types of apples and then the program displays their ratings side by side.
I am only beginning to learn C++ so I'd like to do one thing at a time, but I figured I'd explain what the end goal is.
I've modified your code a little (hope you don't mind), to maybe help make it more clear what I am trying to do.
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 48
|
#include <iostream>
#include <string>
using namespace std;
int main() {
const int num_chars = 5;// what should this number be? The number of items, or the total number of characters in the entire array?
const int min_rating = 0;//Smallest rating we can give
const int max_rating = 6;//Largest rating we can give
string macintosh;
char chars[num_chars] = {macintosh, 'Gala', 'Golden Delicious', 'Granny Smith', 'Fuji'}; //Can this array consist of strings?
int ratings[num_chars] = {0}; //Our ratings, one for each character
string number_strings[max_rating + 1] = {
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine"
};
for (int i = 0; i < num_chars; ++i) {
cout << "Rate character " << chars[i] << " (" << i+1 << "/" << num_chars << "):\t";
do {
cin >> ratings[i];
} while (ratings[i] < min_rating || ratings[i] > max_rating);
}
cout << std::endl;
for (int i = 0; i < num_chars; ++i) {
cout << chars[i] << ":\t" << number_strings[ratings[i]] << std::endl;
}
//Pause
return 0;
}
|