Question: This C++ program is supposed to shift letters a certain amount. For example: 13 Hello, Jack shifts to ----> Uryyb, Whpx. There is an error

This C++ program is supposed to shift letters a certain amount. For example: 13 Hello, Jack shifts to ----> Uryyb, Whpx.

There is an error though. It converts every letter to g and I'm not sure why.

Here is the code:  

#include

#include

#include

using namespace std;

int main(int argc, char * argv[])

{

int c ;

int shift = atoi(argv[1]) ;

c = tolower(cin.get()) ;

while (!cin.eof())

{

if(isalpha(c))

{

c = 'a';

c += shift;

c %= 26;

c += 'a';

}

cout.put(c);

c = tolower(cin.get());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!