Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help but getting error on c++ code on Writing coin dispenser program... #include #include using namespace std; int main() { const int QUARTER =

need help but getting error on c++ code on Writing coin dispenser program...

#include #include using namespace std;

int main() { const int QUARTER = 25; const int DIME = 10; const int NICKEL = 5; const int PENNY = 1; int choice; int q = 0, d(0), n(0), p(0), g(0); //for determining d for dimes, q=quaters, n=nickels, p=pennies, t=total in cents double c;//for cents $.$$ input do { cout << " Choose 1 to input dollar amount to get coins. " << "Choose 2 to input coins and get dollar amount " << "Choose 3 to exit this program " << "Enter your choice and press Return: "; cin >> choice; switch (choice) { case 1:

cout << "Please input dollar amount (*.**) positive numbers only and keep it reasonable of course: "; cin >> c; cout << "you have put $" << c << " in system to calculate "; g = c * 100; cout << "that is " << g << " cents ";

if (g / QUARTER > 1) //checking for quarters { q = g / QUARTER; g = g % QUARTER; } if (g / DIME > 1) //if dimes are remaining this will be checking for dimes here { d = g / DIME; g = g % DIME; } if (g / NICKEL > 1)//if nickels are remaining this will be checking for Nickels here { n = g / NICKEL; g = g % NICKEL;

} if (g / PENNY > 1)//if pennies are remaining this will be checking for pennies here { p = g / PENNY; c = g % PENNY; } cout << " converted quarters = " << q; cout << " converted dimes = " << d; cout << " converted nickels= " << n; cout << " converted pennies = " << p;

//tried to do it another way but pennies are off, this was first way attempted... /*q = g / 25; q = q % 25; cout << "that is " << q << " quarters "; d = q / 10; d = d % 10; cout << "that is " << d << " dimes "; d = d / 5; n = d % 5; cout << "that is " << n << " nickels "; n = n / 1; p = n % 1; cout << "that is " << p << " pennies"; */ break; case 2:

void coins_to_dollar(int quarters, int dimes, int nickels){ //function to convert coins to dollar int total = quarters * 25 + dimes * 10 + nickels * 5; //total amount of coins cout << "You have $" << total / 100 << " and " << total % 100 << " cents." << endl; //print out the dollar amount } int main(){ //main function int quarters, dimes, nickels ; //declare variables cout << "Enter the number of quarters: "; //ask for quarters cin >> quarters; //get quarters cout << "Enter the number of dimes: "; //ask for dimes cin >> dimes; //get dimes cout << "Enter the number of nickels: "; //ask for nickels cin >> nickels; //get nickels coins_to_dollar(quarters, dimes, nickels); //call function return 0; // return 0 }

}

}

}

return; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions