On to functions

--Originally published at Programming

The instruction was:

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

Well is exactly what says the instruction, is like quiz 4#.

function

#WSQ05


Quiz #3

--Originally published at Programming

For this quiz the instruction was:

Create a program with two functions:
  • double square_root(double x) {}  // returns the square root of x
  • double cube_root(double x) {} // returns the cube root of x

You need to include the library <math.h> and use sqrt, cbrt.

 

quiz3

#Quiz03


Quiz week 4

--Originally published at Programming

For this quiz I want you to (in class) create a program with two functions:
  • int minimumThree(int x, int y, int z){ }  // returns the value that is smallest of x, y and z
  • int sumSquares(int x, int y, int z) {}  // returns the value of the sum of squares of x, y, z

     

    There is my quiz! but I be slow to do the program..

quiz4

#Quiz04


SUM OF NUMBERS

--Originally published at Programming

The instruction was:

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.


PICK A NUMBER

--Originally published at Programming

The instruction was :

Write a program that picks a random integer in the range of 1 to 100.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.

You might want to check that your program doesn’t always use the same random number is chosen and you should also split your problem solving into parts. Perhaps only generate the random number and print that as a first step.

 

Basically in this program we have to do a game, is like …you would have to guess the number that i’m thinking between the numbers 1 to 100.

I love it! Because i can play when i’m bored.


F u n with numbers

--Originally published at Programming

For this activity we have to ask the user for two integer values, then use those two values to calculate and show the following:

  • The sum of the two numbers.
  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers

[Some things are very weird of this code, for example the sign of the substraction and the sum.]

 42numbers

#WSQ01


Temperature

--Originally published at Programming

Well,  in this program we have to ask what is the temperature in farenheit to convert it to Celsius.

The instruction was: write a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

I check in the book for the information, like the variables.

I have simple mistakes, for example i forgot to put “;”al last, or put wrong the key “{}”.

celsius

#WSQ02