Trying to make a change calculator.
When running and building the task (VScode), I’m getting an error that it is expecting an initializer before “-=”. Not exactly sure where or why that is being expected.
This is the code right now.
#include <iostream>
using namespace std;
int main() {
const int dollar {100}, quarter {25} , dime {10} , nickel {5}, penny {1};
cout << "Hello, please enter your amount in cents: ";
int customer {0};
cin >> customer;
cout << "Thank you, you entered: " << customer << " cents." << endl;
int dollarChange {customer / dollar};
int total_1 {0} = customer - (dollarChange * dollar);
int quarterChange {total_1 / quarter};
int total_2 {0} -= (quarterChange * quarter);
int dimeChange {total_2 / dime};
int total_3 {0} -= (dimeChange * dime);
int nickelChange {total_3 / nickel};
int total_4 {0} -= (nickelChange * nickel);
int pennyChange {total_4 / penny};
cout << "Your change is: " << endl;
cout << "nQuarters: " << quarterChange << endl;
cout << "Dimes: " << dimeChange << endl;
cout << "Nickels: " << nickelChange << endl;
cout << "Pennies: " <<pennyChange << endl;
return 0;
}
The error message appearing after building the task:
C:ProjectsSection 8main.cpp:41:20: error: expected ',' or ';' before '-=' token
41 | int total_2 {0} -= (quarterChange * quarter);
| ^~
C:ProjectsSection 8main.cpp:44:21: error: expected ',' or ';' before '-=' token
44 | int total_3 {0} -= (dimeChange * dime);
| ^~
C:ProjectsSection 8main.cpp:48:21: error: expected ',' or ';' before '-=' token
48 | int total_4 {0} -= (nickelChange * nickel);
New contributor
Kim Palmquist is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.