do-while loop isn't working help
please help me...the do-while loop will not work
It will go through properly the first time and then the "Want to enter another comes up but if you enter "1" it will ask again "Want to enter another" it won't go through the program...but if you enter "2" it will exit the program
Code:
int main()
{
int again; //user input which determines if they want to enter another sentence
char sentence[81]; //user inputs sentence
do
{
system("cls");
cout << "Do you want to enter a word or sentence up to 80 characters: " << endl;
gets(sentence);
encrypt(sentence); //calls function encrypt
decrypt(sentence); //calls function decrypt
cout << "Want to enter another? (press 1 - Yes, 2 - No)" << endl;
cin >> again;
}
while (again == 1);
return 0;
}
void encrypt(char sentence[])
{
for (int i = 0; i < strlen(sentence); i++)
{
sentence[i] = sentence[i] + 3;
}
cout << sentence << endl;
}
void decrypt(char sentence[])
{
for (int i = 0; i < strlen(sentence); i++)
{
sentence[i] = sentence[i] - 3;
}
cout << sentence << endl;
}