#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
string word;
int num;
cout<< "\nEnter a 6 letter string: "; //display word
cin>> word; //enter 6 letter word
cout << "\nEnter # of character jumps: "; //display number
cin >> num; //enter number of jumps
if (word == "0" && word == "0")
if (word == "5" && word == "5")
cout << "Result: " << word << endl;
}
Hello there I am a beginner about C++ and I'm currently working on my assignment. I wonder why The # of Character jumps doesn't affect the result. A response will be a great help to me. TYSM
Character jumps means that a user will input a number and that will lead to a character jumping for example:
Enter a 6 letter string: abcdef
Enter # of character jumps: 2 //That should make the string of abcdef into cbcdeh because the characters skipped 2 characters each.
Idk but my teacher says to only use if's and it doesn't really make sense.
I have corrected the code but my teacher wont allow me to use these commands because we're not on that topic yet. Here is the correct code.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
string word;
int num;
cout<< "\nEnter a 6 letter string: ";
cin>> word;
cout << "\nEnter # of character jumps: ";
cin >> num;
cout << endl;
my teacher says to only use if's and it doesn't really make sense.
What, exactly, does your assignment say. To change the 1st char and the 6th char (index 0 and 5) doesn't use if ??? Are you expected to cycle from say 'z' back to 'a'? What about lowercase & uppercase input in that case? What precisely is the requirement? If you have say 'y' and jump by 2 you get '{'. Is this what is wanted, or is 'a' expected? If 'Y' is entered is '[' expected or 'A'? What if a non-letter is entered? '1' jump 3 is '4' - or is this invalid input?
Using .at() if the length of the entered string is less than 6 chars will cause a run-time exception. It might be better if the number of entered letters is at least 6