Can You Shift an Array by a User-Inputted Value Using For Loops?

  • Thread starter Thread starter AST3019
  • Start date Start date
  • Tags Tags
    Array Indices
AI Thread Summary
The discussion centers on troubleshooting a for loop in C++ that is intended to shift the index of an array based on user input. The initial code contains a logical error in the for loop condition, using "s == b" instead of a condition that allows the loop to iterate. After realizing this mistake, the user corrected the code, which resolved the issue and allowed the program to function as intended. The conversation highlights the importance of proper loop conditions in programming.
AST3019
Messages
4
Reaction score
0
So I am 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.
 
Technology news on Phys.org
Have a think about why you put s == b in the for loop. It doesn't make any sense at all.
 
yeah, right after i posted the thread i realized that and fixed it and now it works. thanks though.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top