Question
Instructions
Prompt for and accept an unsigned short int value
Display the value of 2 raised to the power of the value input in (1), i.e. display 2n, where n is the value from (1)
Prompt for and accept an unsigned short int value, and assume that this is the radius of a circle
Display the values of the circumference and area of the circle whose radius is given by (3)
Prompt for and accept a float value
Display the value of the polynomial 2x3 + 3x2 + 4x + 5, where x is the value read in (5)
Sample output
Enter unsigned short int: 3
The value of 2 raised to the 3 power is 8
Enter unsigned short int: 5
A circle with radius 5 has circumference of 31.416 and an area of 78.540
Enter a float value: 2.5
The value of 2(2.5)**3 + 3(2.5)**2 + 4(2.5) + 5 = 65
Explanation / Answer
I won't write the program for you, but I will lay down the basis that you'll need to follow to get this assignment done. Let's think about how the assignment will have to work: 1) We're taking input from the user. We'll do this using the "scanf" function. (Read http://www.cplusplus.com/reference/clibrary/cstdio/scanf/ for more information on how this function works) 2) We'll be performing mathematical operations on these value that we've taken in. 3) We'll be printing values to the output. For this, we'll use the "printf" function. (Read http://www.cplusplus.com/reference/clibrary/cstdio/printf/ for more info). When we look at the assignment, we see that each time we take input, we are trying to extract a specific type of value from the user input. This can be done using 'formatting characters' and the scanf function. For example, if we wish to prompt for an unsigned short int value: // On the scanf page, we see that certain formatting characters are used for extracting // certain types of data. We want type 'unsigned' and 'short int'. The chars for this are: // h - short int. u - unsigned. Let's get started! unsigned short int value; // When we scan, we pass in a REFERENCE to value by using the ampersand (&) symbol. This // allows the function to directly modify the value variable. scanf("%hu", &value); Now, if we wish to print out that value: // We don't need to pass value as a reference here as we just want to access the data, not modify it. printf("%hu", value); Good! Now hopefully taking user input makes a little more sense! Let's take a look at how to do the mathematical operations. Let's take a look at the math of doing 2^n. CASE 1: NO external functions allowed. Assume that we've loaded the user input into an unsigned short named value. For this, we'll use a LOOP. In this case, we'll use a for loop. (Read more on for loops here: http://cprogramminglanguage.net/c-for-loop-statement.aspx) So, let's set up our loop. Something like this: // We initialize the value of final to 2. This is so that we can perform number of multiply // operations on it. int final = 2; for (unsigned short int i = 0; i