# Thread: Need help with floating point values

1. ## Need help with floating point values

I am fairly new at C++, taking a 10 wk college course on it. I am having to make a program that asks the user for a number between 5 and 10. then when the number is accepted, you are to take the floating value of the number entered, and ask for that many more numbers. The problem is, I am not sure how you would go about accepting that floating point value. This is what I have so far, but I am stuck from here. Anyone have any guidance? Sorry if I did something incorrectly, im a noob to this stuff. I am not asking anyone to do this for me, or code it up. Just point me in the righht direction and I can figure it out. Im just stumped at this point.

Code:
```int main() {
int num;

do {
cout << "Enter a value in the range of 5 to 10: ";
cin >> num ;
if (num < 5 || num > 10)
cout << "The value entered is not in the proper range; please try again"
<< endl;
cout << " " << endl;
} while (num < 5 || num > 10);

cout << "You entered " << num << endl;

return 0;
}```

2. Are you sure you understand the assignment? How can you enter a floating point number of values? Unless they just want you to practice casting of sorts, this seems rather pointless.

3. Here is the instructions.

Write a C program that will prompt the user to enter a integer value in the range of 5 to 10 (inclusive). If the user doesn't enter a value in that range, you are to display an error message and prompt him again to enter a proper value. This sequence is to continue until he finally enters a value in the proper range. You can assume the user will enter a properly-formatted numeric value.

This is where im at in the program

After the user has entered a value in the range of 5 to 10, you are to accept from the user that number of floating point values (if the user specified seven values, for example, you are to then get seven values from the user, prompting him for each value).

After getting the specified number of values, you are to display the following information about the values entered:

1. The sum of the values
2. The average of these values
3. The largest value entered
4. The smallest value entered

4. So, define a float variable, and cin >> into it, inside a loop that loops "num" times.

5. Hmm, a few things to note:

• This asks you to write a C program, however, you are writing your code in C++. Which language are you really working in?
• The assignment is really asking you to read in an integer and then read as many floating point numbers as the integer represents. Just like how the assignment says, "if the user specified seven values, for example, you are to then get seven values from the user, prompting him for each value".
• This means you need a loop to read the floating point data.
• Since you know that there can only be a maximum of 10 floating point values, you are safe to use an array of size 10, however, if you wanted to be slightly more advanced, you could dynamically allocate a block of memory to hold just the right amount.

6. Thanks for the replies guys, this program is probably not too difficult, bit its racking my brain. The class is on C++, im not sure why it says C in the instructions.

7. Attack the problem in small areas. Ask specific questions when you get stuck. Consider that all you have to do now is write a loop to read in num number of floating point values. Then afterwards, you have to perform the calculations, but focus on reading them into an array for now.