Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. array

array

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestestingbeta-testinghelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hackC
    wrote on last edited by
    #1

    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?

    R D 2 Replies Last reply
    0
    • H hackC

      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?

      R Offline
      R Offline
      Russell
      wrote on last edited by
      #2

      where is the problem?

      1 Reply Last reply
      0
      • H hackC

        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?

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        #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

        H 1 Reply Last reply
        0
        • D David Crow

          #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

          H Offline
          H Offline
          hackC
          wrote on last edited by
          #4

          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).

          D 1 Reply Last reply
          0
          • H hackC

            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).

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            #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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups