Need help with converter program

Hello,

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

cout << "To determine how many pennies, dimes, quarters or nickels, enter\n"; //display message
cout << "MENU\n"
<< "1) Pennies\n"
<< "2) Dimes\n"
<< "3) Quarters\n"
<< "4) Nickels" << endl;

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

system("pause"); // keep window open
return 0; // indicates successful termination
}





@chrisf

Get rid of the return( and ) at the end. You are not using a function here.

EDIT: Also, put single quotes around the numbers after choice ==. As in if ( choice == '1' ) since you're checking a char variable, and not an int.
Last edited on
Topic archived. No new replies allowed.