Self-Exercises HELP!! [PART 2]

I don't get this.... quetions/whatever its saying.

NOTE: () are comments in them.

1)Write a program that reads in the radius of a circle and prints the circle's diameter,circumference and area. (How am I suppose to know D:, there weren't no formula about circles!!)

2)Write a program that reads in five integers and determines and prints the largest and the smallest integers in the group. (I know how to make a program that PRINTS five integers but I don't know about "reads". D:)

3)Write a program that reads an integer and determines and prints whether it is odd or even. (It told me about using modulus operator. I'm still confused about that.... how can you get 7%4 to 3!?)

4) How do I find the average? It told me to make a program that prints the sum,average,large, and small. I know how to do them all but I don't know about the "Average" one. :(
1)Write a program that reads in the radius of a circle and prints the circle's diameter,circumference and area. (How am I suppose to know D:, there weren't no formula about circles!!)

allow for user input of the radius, calculate the diameter, circumference, and area and print them to the screen

2)Write a program that reads in five integers and determines and prints the largest and the smallest integers in the group. (I know how to make a program that PRINTS five integers but I don't know about "reads". D:)

Allow the user to enter 5 numbers, this is done by cin, the opposite of cout. once you get all five, you just run a test that checks to see the largest and smallest in the group

3)Write a program that reads an integer and determines and prints whether it is odd or even. (It told me about using modulus operator. I'm still confused about that.... how can you get 7%4 to 3!?)

The modulus operator returns the remainder. C++ Division of integers only returns a whole number, or integer. Modulus returns the remainder. It can be a value from 0 - (n-1) where n is the number after the modulus operator.

4) How do I find the average? It told me to make a program that prints the sum,average,large, and small. I know how to do them all but I don't know about the "Average" one. :(

The average is simple, you add all of the numbers together and divide by the total number of numbers. obviously you would have to know how to get the sum for that, which again, add them all together. Refer to 2 for the largest/smallest.
Last edited on
1) The formulae for circles are well published. Google then and they'll be there.

2) Reads will be taking in the integers from the user, using cin or getline or something like that.

3) Modulus gives you the remaining amount after division. 4 goes into 7 once, with a remainder of 3. So the modulus operation will return 3. By nature, when numbers are divided by two and have a modulus that is 0, they're even. If not, they're odd.

4) Average is attained by adding up all of the elements then dividing by the number of elements. In the sequence of 1, 2, 3, 4, 5, the average would be (1 + 2 + 3 + 4 + 5) / 5, which would give 3.

Edit: I do believe I've just been Ninja'd.
Last edited on
Those all are basic maths.
Allow the user to enter 5 numbers, this is done by cin, the opposite of cout. once you get all five, you just run a test that checks to see the largest and smallest in the group


How can I find the small and large? I know how to find the "greater to" by using "if" statements with 2 INTEGERS.
Last edited on
A quick Google search will tell you to use a for loop and an array. Compare current to largest encountered, and smallest encountered. If current is larger or smaller, update the largest and smallest encountered variables.
That's more advanced than what the OP knows at this point, at least as far as I know.

The best way to do this is to create two variables:
int large, small;

You have two options as to what you want to define them as also.
1) initialize them as follows:
large should be an extremely small number, and small should be an extremely large number
2) set them equal to the first value entered, then use for loops to check to see if the new number entered is larger or smaller than the variables, respectively.
That's more advanced than what the OP knows at this point, at least as far as I know.

The best way to do this is to create two variables:
int large, small;

You have two options as to what you want to define them as also.
1) initialize them as follows:
large should be an extremely small number, and small should be an extremely large number
2) set them equal to the first value entered, then use for loops to check to see if the new number entered is larger or smaller than the variables, respectively.


Can you give me an example?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
int main() {
   int small, large, num;
   for (int i = 0; i < 5; i ++) {
      std::cout << "Please enter a number: ";
      std::cin >> num;
      if (i = 0) {
         small = num;
         large = num;
      }
      // use if statements to check to see if small is smaller than num
      // also check to see if large is larger
   }
   return 0;
}
Topic archived. No new replies allowed.