My variables are not initializing

Hi all,
this is my first time posting, so this is probably going to sound pretty newbish.

#include <iostream>
using namespace std;

int main(){
float amount;
int cents; // will hold whole amount in cents, not the number of pennies.
int tendered = 0;
int hundreds, fifties, twenties, tens, fives, ones;
int quarters, dimes, nickels, pennies;

cout << "Enter amount to change (e.g. 6.71): ";
cin >> amount;

cents = int(amount * 100); // convert amount to whole number of cents.

hundreds = cents/10000;
tendered = tendered + 10000*hundreds;

fifties = (cents - tendered)/5000;
tendered = tendered + 5000*fifties;

twenties = (cents - tendered)/2000;
tendered = tendered + 2000*twenties;

tens = (cents - tendered)/1000;
tendered = tendered + 1000*tens;

fives = (cents - tendered)/500;
tendered = tendered + 500*fives;

ones = (cents - tendered)/100;
tendered = tendered + 100*ones;

quarters = (cents - tendered)/25;
tendered = tendered + 25*quarters;

dimes = (cents - tendered)/10;
tendered = tendered + 10*dimes;

nickels = (cents - tendered)/5;
tendered = tendered + 5*nickels;

pennies = (cents - tendered)/1;
tendered = tendered + 1*pennies;

cout << "The appropriate change for $" << amount << " is:" << endl
<< "$100 x " << hundreds << endl;
<< "$50 x " << fifties << endl;
<< "$20 x " << twenties << endl;
<< "$10 x " << tens << endl;
<< "$5 x " << fives << endl;
<< "$1 x " << ones << endl;
<< "$0.25 x " << quarters << endl;
<< "$0.10 x " << dimes << endl;
<< "$0.05 x " << nickels << endl;
<< "$0.01 x " << pennies << endl;

return 0;
}

The variables for the pennies, nickels, dimes, and quarters are not initaializing.

I also keep getting these messages:

'project 5.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'project 5.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'project 5.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file

Can any of you guys help me fix this?
Thanks in advance.

cin >> amount;

cents = int(amount * 100); // convert amount to whole number of cents.


They are initialized based on variable cents so it will be useful to print their values to see if they are initialized or not.

1
2
3
4
5
cin >> amount;
cout << amount << "\n";

cents = int(amount * 100); // convert amount to whole number of cents.
cout << cents << "\n";


You're assigning, not initializing.

Your final series of cout statements are not daisy chained because your endl's all have semicolons.

You have nothing at the end of the program to halt execution so you can see the output, so you might want to add that.

Aside from the above, your code has nothing wrong and runs as expected.
Topic archived. No new replies allowed.