Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Input Write a single line comment (using //) that says: Step 4. Input In the main, create an integer variable called readValue. Print out Enter

Input

Write a single line comment (using //) that says: Step 4. Input

In the main, create an integer variable called readValue.

Print out Enter an integer:

Using scanf, read the value entered into readValue.

Print out Value read: , then print the content of readValue. scanf taking the form scanf(%i, &val); would wait for the user to type in a whole number like 2 or 17 and store that value in variable val. The %i indicates that you are getting an integer value from the use. &val indicates to put the value typed in by the user into (already existing) variable val. scanf_s is the more secure version of scanf. It takes a third variable which is the size. This will always be 1 except if you use a string. If you use a string, you would type in the strings size

-1. Compile your code. Make sure you dont have any errors. If so, fix them. Run the executable without debugging.

What happens if you enter an integer number (e.g. 4)?

What happens if you enter a real number (e.g. 33.2)? Why do you get this result?

What happens if you enter a character (e.g. a)? It is important to compile and run your code regularly, to make sure you have no errors and that it behaves the way intended. 5. If/else if/else -

1 Write a single line comment indicating the step number and description. It is a good programming practice to write comments to delimitate parts of your code.

Create a control structure using if and else statements that determines whether the number entered is positive or negative, and outputs the answer. o If value is positive, then print positive, if value is negative, print negative. Compile, run and test your code.

Testing the code means trying out different values that should yield different results. In this case, try numbers that are both positive, negative and zero. Dont forget to print new lines so the printout looks good. We dont want to have everything in a single block. White space is good.

4 6. If/else if/else

- 2 Write a single line comment indicating the step number and description.

Create another control structure that will determine whether the number is an odd or an even number. o Suggestion: use the modulo to solve this problem. Compile, run and test your code.

7. If/else if/else

- 3 Write a single line comment indicating the step number and description.

Create a third control structure that determines if the number can be divided by a prime number below 10 and print that prime number (only the lowest prime number shall be printed). For instance, if you enter the number 12, it should output: can be divided by 2. If you enter the number 9, it should output: can be divided by 3. If you enter the number 13, it should output: cannot be divided by a prime number below 10. o Prime numbers below 10 are 2, 3, 5, and 7. o Again, the modulo is useful here. Compile, run and test your code.

8. If/else if/else

- 4 Write a single line comment indicating the step number and description.

Create four integer variables: password, username, guessPassword, guessUsername. o Usernames are integers here (not strings) because we havent strings yet. o You can consider a string to be the C term for text. Its complicated. o If you want to use a character string, you can make a character array like so:

char a_text[100]; // this will make a variable a_text that is 100 characters long

A call to scanf would be scanf_s(%s, a_text, 99); to put up to 99 characters in it.

printf(My test %s, a_text); would output the text read in.

strcmp (for string compare) is a function to compare two strings. Two strings s1 and s2 would be equal if strcmp(s1, s2) == 0.

Ask the user to input the correct password and username (start by outputting instructions, then reading their answer), and store it in the appropriate variables. We will pretend that this is the input the user would give when creating an account.

5 Ask the user again to input a password and username, this time guessing what their password and username are. This is similar to the user trying to login to the system again. Store this in the appropriate variables. o Like before, start by outputting instructions, then reading their answer.

Create a fourth control structure that determines if the user correctly inputted the username and password. Use the appropriate logic operator to complete this. If they match, welcome the user to the system. Otherwise, indicate the presence of an error in the username/password combination. Compile, run and test your code.

What happens when you input a correct username but an incorrect password?

What happens when you input an incorrect username but a correct password?

Modify the control statement to let the user know about the type of error they did. (whether its the username or the password that they got incorrect -- no need to ask for the password if the username is wrong). Compile, run and test your code. 9. Switch

In the main, write a single line comment indicating the step number and description.

Advanced: Below the main, write a function called switchName that has no arguments and no return value (use the keyword void). Create the prototype to this function towards the top of the file, and the implementation of the function at the bottom.

Not advanced: put the switch statement in main.

Comment out all code in main except the switch statement code writing /* at the top, and */ at the end of the block you want to comment out..

Call the function switchName from main or test the switch statement you put in main. Compile, run and test your code. The function switch name will do the following: display a menu of choices, read an input and display a result that is dependent on the input. Here is the menu it should display: ## Switch Name ## Select one of the following options:

6 1 displays my name

2 displays my year of birth

3 displays my favorite ice cream flavor

4 - What is your selection?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions