I was assigned to write a program in which we are to display the number of ways to make change for a dollar using nickels, dimes, quarters, and fifty-cents. When I run this program its supposed to show a table displaying the amount of nickels, dimes, quarters, and fifty cents needed to make change for a dollar. I have been doing the program for days and I still can't understand it and when I went for tutoring, he wasn't there. This is the program I have so far: `
//Program to display the number of ways to make change for a dollar
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
int nickels,dimes,quarts.fifcnts,way;
double totalCents;
cout<<setw(5)<<"Nickels"<<setw(5)<<"Dimes"<<setw(5)<<"Quarters"<<setw(5)<<"Fifty-Cents"<<endl;
for(nickels=0;nickels<=5;nickels++)
for(dimes=0;dimes<=2;dimes++)
totalCents=nickels*dimes*10;
if(totalCents==25)
{
cout<<"Nickels"<<" "<<dimes<<endl;
way++;
}
for(nickels=0;nickels<=5;nickels++)
for(dimes=0;dimes<=2;dimes++)
for(quarts=0;quarts<=2;quarts++)
{
totalCents=nickels*dimes*10;
if(totalCents==25)
{
cout<<nickels<<" "<<dimes<<endl;
way++;
}
My professor gave us this code to start off our program and I don't understand it very well.
Aucun commentaire:
Enregistrer un commentaire