Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Shifting indices of an array.

  1. Feb 28, 2012 #1
    So Im trying to use for loops to shift the index an array by a user inputted value. The code i have so far is
    printMessage();
    cin >> choice;
    if(choice == 2){
    cout << endl;
    cout <<"Please enter the desired number of shifts:" << endl;
    cin >> b;
    int s;
    for (s = 0; s == b;s++) {
    cout << message[s + b];
    }

    }
    When I try to compile it, it doesn' cout the message. The input from the message occurs earlier in the code.
     
  2. jcsd
  3. Feb 28, 2012 #2

    DrGreg

    User Avatar
    Science Advisor
    Gold Member

    Have a think about why you put s == b in the for loop. It doesn't make any sense at all.
     
  4. Feb 28, 2012 #3
    yeah, right after i posted the thread i realized that and fixed it and now it works. thanks though.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Shifting indices of an array.
  1. Functions and arrays. (Replies: 1)

  2. Help with array (Replies: 5)

  3. C++ Array (Replies: 10)

  4. C# arrays (Replies: 1)

  5. Array storage (Replies: 1)

Loading...