0

You input how many quarters, dimes, nickels, and Pennie’s you have and it should tell you how many dollars and pennies equivalent you have

#include <iostream>

int main() {

    int numQuarters, numNickels, numDimes,   numPennies;
    std::cout<<"Please enter the number of coins:"<<std::endl<<"# of quarters: "<<std::endl;
    std::cin>>numQuarters;
  
    std::cout<<"# of nickels: "<<std::endl;
    std::cin>>numNickels;
  
    std::cout<<"# of dimes: "<<std::endl;
    std::cin>>numDimes;

    std::cout<<"# of pennies: "<<std::endl;
    std::cin>>numPennies;

    double quarters=0.25*numQuarters;
    double nickels=0.05*numNickels;
    double dimes=0.10*numDimes;
    double pennies=0.01*numPennies;

    double totalMoney=quarters+nickels+dimes+pennie;
    int dollars=(int)(totalMoney);
    double cents=(double)((totalMoney-   dollars)*100);

    std::cout<<"The total is "<<dollars<<"  dollars and "<<cents<<" cents."<<std::endl;
  
return 0;
    
}
463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
  • 1
    please include input, output and expected output in the quesiton – 463035818_is_not_an_ai Aug 22 '22 at 08:57
  • https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency ; doing all your computations with ints and in cents would be more reliable. – Mat Aug 22 '22 at 08:59
  • 2
    Don't use floating point when trying to process integer values; it's almost always a mistake and requires some expertise in floating point accuracy and conversions. – Richard Critten Aug 22 '22 at 09:00
  • Hard to answer when you don't say what the input is or what the output you get is. – john Aug 22 '22 at 09:20
  • One problem with counting money in floating point is that `0.1 + 0.2 != 0.3`! See [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – BoP Aug 22 '22 at 09:23

0 Answers0