I'm brand new to C++, yet I have experience in many other languages. This script I wrote prompts the user for a change amount, then calculates the amounts of each coin that amount is. For example, 37 cents is 1 quarter, 1 dime, and 2 pennies. I have a while loop but it keeps looping when it shouldn't
Code:
#include <iostream>
using namespace std;
int main(){
double input=0.00;
int quarters=0;
int pennies=0;
int dimes=0;
int nickels=0;
cout<<"Enter the amount you wish to convert: ";
cin>>input;
do{
if(input>0.25){
quarters++;
input-=0.25;
}
else if(input>0.10){
dimes++;
input-=0.10;
}
else if(input>0.05){
nickels++;
input-=0.05;
}
else if(input>0.01){
pennies++;
input-=0.01;
}
}while(input>0.00);
cout<<"\n"<<quarters<<" quarters, "<<dimes<<" dimes, "<<nickels<<" nickels, and "<<pennies<<" pennies.\n";
}
Comment