Issues with array and the output it displays

hi, I'm having trouble getting the output I'm trying to get. i don't know if the issues are in the if statements or how i declared the variables. My code looks like this.
#include <iostream>
#include <iomanip>
using namespace std;

void coin();
double amount[]= {0.25,0.10,0.25,0.05,0.50,0.25,.01,0.10,0.10,0.05,
0.01,0.25,1.00,0.05,0.05,0.10,0.25,0.10,0.01,0.25,
0.10,0.05,0.05,0.05,0.01,0.01,1.00,0.01,0.25,0.05,
0.10,0.25,0.01,0.10,0.05,0.05,0.25,0.10,0.50,0.25,
0.01,0.05,0.25,0.05,0.10,0.10,0.05,0.25,0.05,0.25,
0.05,0.01,0.05,0.25,0.25,0.01,0.05,0.05,0.25,0.05,
0.10,0.10,0.10,0.05,0.25,0.10,0.01,0.05,0.01,0.05,
0.01,1.00,0.25,0.25,0.25,0.10,0.10,0.01,0.01,0.25,
0.10,0.25,0.05,0.25,0.25,0.05,0.01,0.25,0.05,0.05,
0.25,0.01,0.05,0.05,0.05,0.25,0.05,0.25,0.25,0.10,
0.10,0.05,0.05,0.10,0.10,0.10,1.00,0.50,0.25,0.25,
0.01,0.25,0.05,0.01,0.50,0.50,0.05,0.10,0.05,0.05,
0.05,0.10,0.25,0.05,0.25,0.10,0.10,0.25,0.01,0.01,
0.05,0.01,0.01,0.01,0.05,0.25,0.05,0.50,0.10,0.01,
0.01,0.10,0.10,0.05,0.01,0.10,0.10,0.50,1.00,0.05,
0.10,0.25,0.25,0.10,0.01,0.50,0.25,0.25,0.05,0.01,
0.25,0.05,0.05,0.10,0.25,0.10,0.05,0.25,0.25,0.05,
1.00,0.25,0.10,0.25,0.05,0.50,0.01,0.10,0.05,0.25,
0.01,0.10,0.25,0.25,0.01,0.10,0.05,0.25,0.25,1.00,
0.05,0.05,0.01,0.05,0.10,1.00,0.01,0.05,0.01,1.00};

int main()
{
coin();
return 0;
}

void coin() {
int i;
int penny = 0;
int nickel = 0;
int dime = 0;
int quarter = 0;
int half_dollar = 0;
double total_penny = 0;
double total_nickel = 0;
double total_dime = 0;
double total_quarter = 0;
double total_halfdollar = 0;
int invalid = 0;
int total_invalid = 0;
double subtotal,tax,total;

for (i = 0; i < sizeof(amount) / 8; i++) {
if(amount[i] == 0.01){
total_penny += amount[i];
penny++;
}else if(amount[i] == 0.05){
total_nickel += amount[i];
nickel++;
}else if(amount[i] == 0.10){
total_dime += amount[i];
dime++;
}else if(amount[i] == 0.25){
total_quarter += amount[i];
quarter++;
}else if(amount[i] == 0.50){
total_halfdollar += amount[i];
half_dollar++;
}else if(amount[i] == 1.00){
total_invalid += amount[i];
invalid++;
}
subtotal = total_penny + total_nickel + total_dime + total_quarter + total_halfdollar;
tax = subtotal * 0.09;
total = subtotal + tax;


cout << "Amount coins input:" << sizeof(amount)/sizeof(amount[0]) << " coins" << endl;
cout << "You have input: " << half_dollar << " half-dollars" << endl;
cout << "You have input: " << quarter << " quarters" << endl;
cout << "You have input: " << dime << " dimes" << endl;
cout << "You have input: " << nickel << " nickels" << endl;
cout << "You have input: " << penny << " pennies" << endl;
cout << "You have input: " << invalid << endl;
cout << "----------------------------------------------" << endl;
cout << "Amount each coin type" << endl;
cout << "One cent: $" << total_penny << endl;
cout << "Nickel: $" << total_nickel << endl;
cout << "Dime: $" << total_dime << endl;
cout << "Quarter: $" << total_quarter << endl;
cout << "Half-Dollar: $" << total_halfdollar << endl;
cout << "Others: " << total_invalid << endl;
cout << "----------------------------------------------" << endl;
cout << "Subtotal: $" << subtotal << endl;
cout << "Tax (9.0%): " << tax << endl;
cout << "Total: $" << total << endl;
return;
}
}

and when i run it, it gives me

Amount coins input:200 coins
You have input: 0 half-dollars
You have input: 1 quarters
You have input: 0 dimes
You have input: 0 nickels
You have input: 0 pennies
You have input: 0
----------------------------------------------
Amount each coin type
One cent: $0
Nickel: $0
Dime: $0
Quarter: $0.25
Half-Dollar: $0
Others: 0
----------------------------------------------
Subtotal: $0.25
Tax (9.0%): 0.0225
Total: $0.2725


any help would be appreciated
You have a } in the wrong place.

The } at line 93 should be after line 68. This is causing you to exit the for loop on the first iteration. If you used reasonable indentation, this would be obvious.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.



Topic archived. No new replies allowed.