Need help to correct my code! I have home work deadline 3 days!

Write a C++ code that reads from the keyboards a set of 10 numbers, which are for instance are counting for some money in a box. Calculate the number of five cent pieces and find how much is there in dollars.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 #include <iostream>
using namespace std;

int main(){
    int number, dollars; // creates integer for dollar input
       for(int i = 0; i < 10; i++)
               cin >> number;
    if ( number == 5){
      number+=1;
    } 
    else {
        dollars = number * 5 / 100;
    }
        cout << "The result is:" << dollars << endl;
return 0;
}
Last edited on
Please, explain each piece of your code. That helps you to verify your logic.

Your problem description is not clear.
I'm new in C++, i try by myself to do somthing by join piece of codes -- so the question is to Write a C++ code that reads from the keyboards a set of 10 numbers, which are for instance are counting for some money in a box. Calculate the number of five cent pieces and find how much is there in dollars.
Last edited on
Anyone who can help me ??
GranitN wrote:
a set of 10 numbers

You need a container that will hold 10 numbers. For introductory courses, this usually means arrays. Are you familiar with arrays? Does this sound like something you've done in class?

In the code you've shown, you are correctly looping 10 times and reading a number, but you are erroneously reading into the same variable, so the only value you end up keeping is the very last one the user enters.

Can you show some sample input and output? You don't have to know how to do it in your code right now, but you do need to understand your goal. Perhaps some sample inputs and expected outputs will help others help you.
"10 numbers". What are the valid values for a number? What does a number represent?

An array might not be necessary, depending what the input is.
Should be any number just ten number
NUmber should be enter by keyboard how to create that kind of code ??
1. Programs read standard input rather than keyboard.
2. You alreadu do read numbers, like booradley60 did point out.

If "any number", then I just got -7. What do I win? You did not tell yet, what a number means.
Topic archived. No new replies allowed.