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>
usingnamespace 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;
}
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.
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.