Question: Lecture: Functions 5 : Getting Valid User Input and Functions 6 : Changing Parameter Values Objective: Practice implementing functions for the complete Caesar Cipher program
Lecture: Functions : Getting Valid User Input and Functions : Changing Parameter Values
Objective: Practice implementing functions for the complete Caesar Cipher program
Problem Refactor the left or right shift user input
Note: Youll probably find the Functions : Getting Valid User Input lecture useful as you solve the next couple of problems.
Download the Graded Exercise Materials zip file from Canvas and unzip it somewhere on your computer.
Create a new C project named whatever you want in Visual Studio using the Windows Desktop Wizard or in Xcode.
If you're using Visual Studio, add the main.c file from the materials zip file to your project. If youre using Xcode, Xcode automatically generates a main.c file for you; copy and paste the contents of the main.c file from the materials zip file over the one in your Xcode project.
Above the main function, write the following function prototype:
char getValidShiftDirection;
This function gets the character l or the character r from the user.
Below the main function, implement the body of the getValidShiftDirection function. The code that does this is already implemented in the main function, so it makes sense to cut the code from the main function and add it to the body of the getValidShiftDirection function. Youll also need to declare a local variable in the function as well to hold the users shift response, and youll need to return the users shift response from the function once theyre provided a valid response. Because the getValidShiftDirection function returns a char, you'll want to put that returned value into the already existing shiftResponse variable in the main function where you used to have the code you moved into the function. In other words, you should include
shiftResponse getValidShiftDirection;
at that location in the main function
Test your code to make sure it still works properly.
Problem Refactor the shift amount user input
Above the main function, write the following function prototype:
int getValidShiftAmount;
This function gets a shift amount between and inclusive.
At the end of the main.c file, implement the body of the getValidShiftAmount function. Make the appropriate changes to call the getValidShiftAmount function from the main function.
Test your code to make sure it still works properly.
Problem Refactor the message to be encrypted user input
Note: Youll probably find the Functions : Changing Parameter Values lecture useful as you solve this problem.
Above the main function, write the following function prototype:
void getValidMessagechar message, int messageSize;
This function gets a valid message to be encrypted. Notice that the parameter is a pointer to a char; in the lecture we passed in a pointer to an int.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
