I need some help with a program that I am working on.
The program is a executable monetary conversion program
I need my utility to converts dollars to coins.
Must include:
Whole dollars only. If value is less than 1 or 0, the program should break or exit.
Below is the source code I have so far but I cannot seem to get the program to run correctly. No matter what dolloar amount or option I choose, the result message is always "The result is:0's in4 press any number to continue
Below is the source code I am using for this program:
#include <iostream>
using std::cout; // program uses cout
using std::cin; // proram uses cin
using std::endl; // program uses endl
int main() // function main begins program execution
{
int money; // creates integer for money input
const int PENNY = 1; // creates constant integer for penny
const int DIME = 10; // creates constant integer for dime
const int QUARTER = 25; // creates constant integer for quarter
const int NICKEL = 5; // creates constant integer for nickel
int total = 0; //answer for amount is money * 100 / choice
cout << "Please enter in a dollar amount to convert it to change\n"; //prompts user
cin >> money; // user enters dollar amount
char choice;
cin >> choice;
{
if ( money <= 1 ) // if dollar amount if 1 or less end loop
return -1;
else if ( choice == 1 ) // if user types penny then
return ( total = ( money * 100 ) / PENNY ); // divide money by coin
else if ( choice == 2 ) // if user types nickel then
return ( total = ( money * 100 ) / DIME ); // divide money by coin
else if ( choice == 3 ) // if user types dime then
return ( total = ( money * 100 ) / QUARTER ); // divide money by coin
else if ( choice == 4 ) //if user types quarter
return ( total = ( money * 100 ) / NICKEL ); // divide money by coin
}
cout << "The result is:" << total <<"'s in" << choice << endl; // display message with amount from m * 100 / c