Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:35:05+00:00 2026-06-12T07:35:05+00:00

Problem: Write a program that prompts the user to enter some number of 1,

  • 0

Problem:
Write a program that prompts the user to enter some number of 1, 2, 5, 10, 20, 50 and 100 dollar bills. Query the user separately for the number of each size dollar.

I think I’ve completed the code pretty well but the last part of the question states:
Modify your program to use an initializer list for the vector, and use a range-based for statement to traverse the vector. Note: These C++11 features are available in g++-4.6 and Visual Studio 2012, but may not be available on other compilers.

I don’t understand what the last part is asking. Hopefully someone here can point me in the right direction. This is a C++ class and my book doesn’t have the newest version.

Any critique on my code format would also be great!

Here is my code:

 #include "std_lib_facilities_3.h"
    vector<int>bills;
    int bill;
    int bill_tot(){
        int sum = 

    1*bills[0]+2*bills[1]+5*bills[2]+10*bills[3]+20*bills[4]+50*bills[5]+100*bills[6];
            return sum;
        }
    int main()
    try{
        cout << "Enter the number of One Dollar Bills you have: ";
        cin >> bill;
        cout << '\n';
        bills.push_back(bill);
        if (bill<0)
            error("You can't have a negative value.\n");

        cout << "Enter the number of Two Dollar Bills you have: ";
        cin >> bill;
        cout << '\n';
        bills.push_back(bill);
        if (bill<0)
            error("You can't have a negative value.\n");

        cout << "Enter the number of Five Dollar Bills you have: ";
        cin >> bill;
        cout << '\n';
        bills.push_back(bill);
        if (bill<0)
            error("You can't have a negative value.\n");

        cout << "Enter the number of Ten Dollar Bills you have: ";
        cin >> bill;
        cout << '\n';
        bills.push_back(bill);
        if (bill<0)
            error("You can't have a negative value.\n");

        cout << "Enter the number of Twenty Dollar Bills you have: ";
        cin >> bill;
        cout << '\n';
        bills.push_back(bill);
        if (bill<0)
            error("You can't have a negative value.\n");

        cout << "Enter the number of Fifty Dollar Bills you have: ";
        cin >> bill;
        cout << '\n';
        bills.push_back(bill);
        if (bill<0)
            error("You can't have a negative value.\n");

        cout << "Enter the number of One Hundred Dollar Bills you have: ";
        cin >> bill;
        cout << '\n';
        bills.push_back(bill);
        if (bill<0)
            error("You can't have a negative value.\n");


        cout << "You have " << bills[0] <<" One Dollar Bills.\n";
        cout << "You have " << bills[1] <<" Two Dollar Bills.\n";
        cout << "You have " << bills[2] <<" Five Dollar Bills.\n";
        cout << "You have " << bills[3] <<" Ten Dollar Bills.\n";
        cout << "You have " << bills[4] <<" Twenty Dollar Bills.\n";
        cout << "You have " << bills[5] <<" Fifty Dollar Bills.\n";
        cout << "You have " << bills[6] <<" One Hundred Dollar Bills.\n";
        cout << "The value of all your Dollar Bills are $" << bill_tot() << endl;
        keep_window_open();
    }
    catch (runtime_error e) {   
        cout << e.what() << '\n';
        keep_window_open();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:35:06+00:00Added an answer on June 12, 2026 at 7:35 am

    This is illustrative code:

    std::vector<int> denomination { 1,2,5,20,50,100}; // Initializer list for vector
    int sum = 0;
    int number;
    for ( int bill : denomination ) // range-based for loop
    {
        cout << "Enter the number of $" << bill << " you have: ";
        cin >> number;
        sum += number * bill;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a javascript program that will ask the user to enter
When I write a C program, I encountered a problem that is as follows:
I'm trying to write a Greek vocabulary quiz program. The problem is that I
Problem: Write a program Deal.java that takes an command-line argument N and prints N
For those who don't know, FizzBuzz is the following problem: Write a program that
The Problem I've been trying to write a program that logs uncaught exceptions and
Ok, so I'm new to VB.NET and trying to write a program that prompts
Write a program that randomly selects from a bag of eight objects. Each object
I need some help in getting this right, problem Write a function which takes
My program collects the number of bottles collected by four rooms. When the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.