array
-
This is the array program I made last night.
/* A stupid array program that I made when I was bored one night */ #include iostream using namespace std; int main() { const size_t arsize = 27; int a[arsize] = {0,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,}; a[0] = 'a'; a[1] = 'b'; a[2] = 'c'; a[3] = 'd'; a[4] = 'e'; a[5] = 'f'; a[6] = 'g'; a[7] = 'h'; a[8] = 'i'; a[9] = 'j'; a[10] = 'k'; a[11] = 'l'; a[12] = 'm'; a[13] = 'n'; a[14] = 'o'; a[15] = 'p'; a[16] = 'q'; a[17] = 'r'; a[18] = 's'; a[19] = 't'; a[20] = 'u'; a[21] = 'v'; a[22] = 'w'; a[23] = 'x'; a[24] = 'y'; a[25] = 'z'; a[26] = ' '; int input; string cool; int end = 99; cout << "Programmed By Cody Rentschler\n" << endl; cout << "Alphabit Array testing." << endl; cout << "Numbers 0 - 26 only." << endl; cout << "Input 99 to exit out of loop." << endl; for (int can = 0; can != 1000000; cool.push_back(a[input])) { cin >> input; cin.ignore(100,'\n'); if (input == end) // To get out of for loop { break; } if (input > 26) { cout << "Error: Number to big" << endl; cin.get(); system("cls"); return main(); } if (input < 0) { cout << "Error: Number to small" << endl; cin.get(); system("cls"); return main(); } ++can; } cout << "\n\n\n\n" << endl; cout << cool << endl; cin.get(); return 0; }
Is this and example of how an array works or am I using this function wrong. Just wondering because i'm trying to figure out how arrays work. Or is there an easier way to do this same program? -
This is the array program I made last night.
/* A stupid array program that I made when I was bored one night */ #include iostream using namespace std; int main() { const size_t arsize = 27; int a[arsize] = {0,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,}; a[0] = 'a'; a[1] = 'b'; a[2] = 'c'; a[3] = 'd'; a[4] = 'e'; a[5] = 'f'; a[6] = 'g'; a[7] = 'h'; a[8] = 'i'; a[9] = 'j'; a[10] = 'k'; a[11] = 'l'; a[12] = 'm'; a[13] = 'n'; a[14] = 'o'; a[15] = 'p'; a[16] = 'q'; a[17] = 'r'; a[18] = 's'; a[19] = 't'; a[20] = 'u'; a[21] = 'v'; a[22] = 'w'; a[23] = 'x'; a[24] = 'y'; a[25] = 'z'; a[26] = ' '; int input; string cool; int end = 99; cout << "Programmed By Cody Rentschler\n" << endl; cout << "Alphabit Array testing." << endl; cout << "Numbers 0 - 26 only." << endl; cout << "Input 99 to exit out of loop." << endl; for (int can = 0; can != 1000000; cool.push_back(a[input])) { cin >> input; cin.ignore(100,'\n'); if (input == end) // To get out of for loop { break; } if (input > 26) { cout << "Error: Number to big" << endl; cin.get(); system("cls"); return main(); } if (input < 0) { cout << "Error: Number to small" << endl; cin.get(); system("cls"); return main(); } ++can; } cout << "\n\n\n\n" << endl; cout << cool << endl; cin.get(); return 0; }
Is this and example of how an array works or am I using this function wrong. Just wondering because i'm trying to figure out how arrays work. Or is there an easier way to do this same program? -
This is the array program I made last night.
/* A stupid array program that I made when I was bored one night */ #include iostream using namespace std; int main() { const size_t arsize = 27; int a[arsize] = {0,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,}; a[0] = 'a'; a[1] = 'b'; a[2] = 'c'; a[3] = 'd'; a[4] = 'e'; a[5] = 'f'; a[6] = 'g'; a[7] = 'h'; a[8] = 'i'; a[9] = 'j'; a[10] = 'k'; a[11] = 'l'; a[12] = 'm'; a[13] = 'n'; a[14] = 'o'; a[15] = 'p'; a[16] = 'q'; a[17] = 'r'; a[18] = 's'; a[19] = 't'; a[20] = 'u'; a[21] = 'v'; a[22] = 'w'; a[23] = 'x'; a[24] = 'y'; a[25] = 'z'; a[26] = ' '; int input; string cool; int end = 99; cout << "Programmed By Cody Rentschler\n" << endl; cout << "Alphabit Array testing." << endl; cout << "Numbers 0 - 26 only." << endl; cout << "Input 99 to exit out of loop." << endl; for (int can = 0; can != 1000000; cool.push_back(a[input])) { cin >> input; cin.ignore(100,'\n'); if (input == end) // To get out of for loop { break; } if (input > 26) { cout << "Error: Number to big" << endl; cin.get(); system("cls"); return main(); } if (input < 0) { cout << "Error: Number to small" << endl; cin.get(); system("cls"); return main(); } ++can; } cout << "\n\n\n\n" << endl; cout << cool << endl; cin.get(); return 0; }
Is this and example of how an array works or am I using this function wrong. Just wondering because i'm trying to figure out how arrays work. Or is there an easier way to do this same program?#hackC++ wrote:
...am I using this function wrong.
What function?
#hackC++ wrote:
Or is there an easier way to do this same program?
First you need to explain exactly what it is that you are trying to do.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
-
#hackC++ wrote:
...am I using this function wrong.
What function?
#hackC++ wrote:
Or is there an easier way to do this same program?
First you need to explain exactly what it is that you are trying to do.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
What function? The array function or whatever an array does (I don't understand arrays) What I'm trying to do is that when I type the number that corresponds to it's place in the alphabit it will print whatever letter coreesponds to the number, to a string. for example if I input 6, 4, 11, 11, 14 the program will output "hello". Just wondering if this is the ideal way of doing this. (by ideal I mean using an array).
-
What function? The array function or whatever an array does (I don't understand arrays) What I'm trying to do is that when I type the number that corresponds to it's place in the alphabit it will print whatever letter coreesponds to the number, to a string. for example if I input 6, 4, 11, 11, 14 the program will output "hello". Just wondering if this is the ideal way of doing this. (by ideal I mean using an array).
#hackC++ wrote:
(I don't understand arrays)
Then I would suggest familiarizing yourself with them. See here.
#hackC++ wrote:
What I'm trying to do is that when I type the number that corresponds to it's place in the alphabit...for example if I input 6, 4, 11, 11, 14 the program will output "hello".
That should be 7, 4, 11, 11, and 14.
#hackC++ wrote:
Just wondering if this is the ideal way of doing this. (by ideal I mean using an array).
Not really. I would opt for something like:
int number;
std::cin >> number;
std::cout << (char) number << std::endl;
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb