Can some help me with a C++ program in Visual Basic?
In this assignment, you will write a program that: Calculates the fewest number of coins required to dispense change from a vending machine. Indicates the numbers of quarters, dimes, nickels, and pennies dispensed from the vending machine. Creates a control table naming each control on the interface and identifying the key events. Creates a data table identifying the variables. Save your program as Dispense.cpp.
This type of problem screams for modulo arithmetic so let's make some variables first. I am going to set the change equal to 67 cents and initialize the counts to 0. change = 67 num_coins = 0 num_quarters =0 num_dimes = 0 num_nickels = 0 num_pennies = 0 num_quarters += change // 25 <-- This integer division adds 2 to num_quarters change -= 25 * num_quarters <-- update change left to give out to 17 num_dimes += change // 10 change -= 10 * num_dimes num_nickels += change // 5 change -= 5 * num_nickels num_pennies += change num_coins = num_quarters + num_dimes + num_nickels + num_pennies
Okay so that being said my ending of the program should look something like this then. private: System::Void btnDispense_Click(System::Object^ sender, System::EventArgs^ e) { double amount; int q, d, n, p; // Variables to hold calculations //parse textbox to get number amount = Convert::ToDouble(txtInput->Text); // Convert to number of pennies to avoid precision errors amount = amount * 100; // check quarters q = amount/25; // Number of quarters txtQuarters->Text = Convert::ToString(q); // Display on Screen amount = amount-(q*25); // Amount after quarters taken out //THEN DIMES, NICKELS, AND… //check pennies p = amount/1; // Number of pennies txtPennies->Text = Convert::ToString(p); // Display on Screen amount = amount-(p*1); // Amount after pennies taken out. SHOULD BE 0 // return 0; }
looks like it would work
Okay thanks.
Join our real-time social learning platform and learn together with your friends!