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

  • Home
  • SEARCH
  • 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 7897533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:11:26+00:00 2026-06-03T08:11:26+00:00

I’m working on a project and have written code that determines how much money

  • 0

I’m working on a project and have written code that determines how much money is spent in one day – the only problem is that I need to make it so the day 1 totals are outputted, then day 2 starts (with just the day 2 totals outputted), and then day 3 starts (with just the day 2 totals outputted) and then after all 3 days have ended, a total of totals from the 3 days is outputted. I’ll paste my code in, but for some reason the formatting is messed up. Thank you!

void drillDay ()
{
    int dayCounter = 1;
    while (dayCounter > 0)
    {
        //Enlisted Soldiers, total number of Soldiers who attend
        int privatesRankOneTotal = 0;
        int privatesRankTwoTotal = 0;
        int privatesRankThreeTotal = 0;
        int specialistsCorporalsTotal = 0;
        int sergeantsTotal = 0;
        int staffSergeantsTotal = 0;
        int pltSergeantsTotal = 0;
        int masterSergeantsTotal = 0;

    //Warrant Officers, total number of Warrant Officers who attend
    int chiefWarrantRankOneTotal = 0;
    int chiefWarrantRankTwoTotal = 0;
    int chiefWarrantRankThreeTotal = 0;

    //Officers, total number of officers who attend
    int ltRankTwoTotal = 0;
    int ltRankOneTotal = 0;
    int captainsTotal = 0;

    //How much each soldier is paid per day, based on rank.
    double pvtOnePay = 99.40;
    double pvtTwoPay = 111.42;
    double pfcPay = 117.16;
    double SpcCplPay = 136.42;
    double sgtPay = 165.84;
    double ssgPay = 229.12;
    double sfcPay = 239.32;
    double msgPay = 309.44;

    double cwoOnePay = 233.40;
    double cwoTwoPay = 274.92;
    double cwoThreePay = 336.04;

    double ltTwoPay = 188.56;
    double ltOnePay = 294.96;
    double cptPay = 335.40;

    cout<<endl<<"Enter amount of enlisted soldiers:"<<endl<<endl;

    cout<<"How many Privates (E-1) / (PVT) are attending drill today?  "<<endl;
    cin>>privatesRankOneTotal;
    cout<<"How many Privates (E-2) / (PV2) are attending drill today?  "<<endl;
    cin>>privatesRankTwoTotal;
    cout<<"How many Privates (E-3) / (PFC) are attending drill today?  "<<endl;
    cin>>privatesRankThreeTotal;
    cout<<"How many Specialists / Corporals (E-4) / (SPC / CPL) are attending drill today? ";
    cin>>specialistsCorporalsTotal;
    cout<<"How many Sergeants (E-5) / (SGT) are attending drill today?  "<<endl;
    cin>>sergeantsTotal;
    cout<<"How many Staff Sergeants (E-6) / (SSG) are attending drill today?  "<<endl;
    cin>>staffSergeantsTotal;
    cout<<"How many Platoon Sergeants (E-7) / (SFC) are attending drill today?  "<<endl;
    cin>>pltSergeantsTotal;
    cout<<"How many soldiers with the paygrade of (E-8) are attending drill today?  "<<endl;
    cin>>masterSergeantsTotal;

    cout<<endl<<endl<<endl;

    cout<<"Enter amount of Warrant Officers:"<<endl<<endl;

    cout<<"How many Warrant Officers (W-1) / (WO1) are attending drill today?  "<<endl;
    cin>>chiefWarrantRankOneTotal;
    cout<<"How many Warrant Officers  (W-2) / (CW2) are attending drill today?  "<<endl;
    cin>>chiefWarrantRankTwoTotal;
    cout<<"How many Warrant Officers (W-3) / (CW3) are attending drill today?  "<<endl;
    cin>>chiefWarrantRankThreeTotal;

    cout<<endl<<endl<<endl;

    cout<<"Enter amount of Officers:"<<endl<<endl;

    cout<<"How many 2nd Lieutenants (O-1) / (2LT) are attending drill today?  "<<endl;
    cin>>ltRankOneTotal;
    cout<<"How many 1st Lieutenants  (O-2) / (1LT) are attending drill today?  "<<endl;
    cin>>ltRankTwoTotal;
    cout<<"How many Officers with paygrade (O-3) / Rank (CPT) are attending drill today?  "<<endl;
    cin>>captainsTotal;
    cout<<endl<<endl<<endl;

    int totalEnlistedSoldiers = privatesRankOneTotal + privatesRankTwoTotal + privatesRankThreeTotal + specialistsCorporalsTotal + sergeantsTotal + staffSergeantsTotal + pltSergeantsTotal + masterSergeantsTotal;
    cout<<"Total enlisted soldiers at drill today:  "<<totalEnlistedSoldiers<<endl<<endl;

    int totalWarrantOfficers = chiefWarrantRankOneTotal + chiefWarrantRankTwoTotal + chiefWarrantRankThreeTotal;
    cout<<"Total Warrant Officers at drill today:  "<<totalWarrantOfficers<<endl<<endl;

    int totalOfficers = ltRankOneTotal + ltRankTwoTotal + captainsTotal;
    cout<<"Total Officers at drill today:  "<<totalOfficers<<endl<<endl;

    int totalSoldiers = totalEnlistedSoldiers + totalWarrantOfficers + totalOfficers;
    cout<<"Total soldiers (Enlisted, Warrant Officers, and Officers) at drill today:  "<<totalSoldiers<<endl;

    double privateOneTotalPay = privatesRankOneTotal*pvtOnePay;
    double privateTwoTotalPay = privatesRankTwoTotal*pvtTwoPay;
    double privateThreeTotalPay = privatesRankThreeTotal*pfcPay;
    double spcCplTotalPay = specialistsCorporalsTotal*SpcCplPay;
    double sgtTotalPay = sergeantsTotal*sgtPay;
    double ssgTotalPay = staffSergeantsTotal*ssgPay;
    double sfcTotalPay = pltSergeantsTotal*sfcPay;
    double msgTotalPay = masterSergeantsTotal*msgPay;

    double cwoOneTotalPay = chiefWarrantRankOneTotal*cwoOnePay;
    double cwoTwoTotalPay = chiefWarrantRankTwoTotal*cwoTwoPay;
    double cwoThreeTotalPay = chiefWarrantRankThreeTotal*cwoThreePay;

    double ltOneTotalPay = ltRankTwoTotal*ltTwoPay;
    double ltTwoTotalPay = ltRankOneTotal*ltOnePay;
    double cptTotalPay = captainsTotal*cptPay;

    double totalSoldiersDrillPay = privateOneTotalPay + privateTwoTotalPay + privateThreeTotalPay + spcCplTotalPay + sgtTotalPay + ssgTotalPay + sfcTotalPay + msgTotalPay + cwoOnePay + cwoTwoPay + cwoThreePay + ltOnePay + ltTwoPay + cptPay;
    cout<<endl<<endl<<endl;

    double costOfLunch = 14.99;
    int soldiersProvidedLunch = 0;
    int loopCounter = 1;


    cout<<"How many soldiers were provided lunch today?"<<endl;
    cin>>soldiersProvidedLunch;
    cout<<endl;

    double totalLunchCost = soldiersProvidedLunch*costOfLunch;


    while (loopCounter == 1)
    {
        if (soldiersProvidedLunch <= totalSoldiers)
        {
            cout<<endl<<soldiersProvidedLunch<<" were provided lunch, the total cost of lunch today will be $"<<setiosflags(ios::fixed) << setprecision(2)<<totalLunchCost;
            loopCounter --;
        }
        else
        {
            cout<<totalSoldiers<<" soldiers were at drill today, there cannot be more."<<endl<<endl;
            cout<<"Enter the number of soldiers that were provided lunch today."<<endl;
            cin>>soldiersProvidedLunch;
        }
    }

    cout<<endl<<endl<<endl;


    double gasPrice = 3.87;
    double gallonsPumped = 0;

    cout<<"How many gallons of gasoline were purchased today:"<<endl;
    cin>>gallonsPumped;
    double finalGasPrice = gasPrice*gallonsPumped;

    cout<<endl;

    if (gallonsPumped >= 1)
    {
        cout<<endl<<"The total cost for gasoline today was $"<<setiosflags(ios::fixed) << setprecision(2) << finalGasPrice<<"."<<endl;
    }
    else
    {
        cout<<"No money spent on gasoline today.";
    }

    double dayDrillCost = finalGasPrice+totalLunchCost+totalSoldiersDrillPay;


    cout<<endl<<endl<<endl<<"Totals for today: "<<endl<<"**************************************"<<endl;
    cout<<"Total pay for soldiers present: $"<<setiosflags(ios::fixed) << setprecision(2)<<totalSoldiersDrillPay<<endl;
    cout<<"Total amount of money spent on lunch: $"<<setiosflags(ios::fixed) << setprecision(2)<<totalLunchCost<<endl;
    cout<<"Total amount of money spent on gas: $"<<setiosflags(ios::fixed) << setprecision(2)<<finalGasPrice<<endl<<"**************************************"<<endl;
    cout<<"Cost of drill today: $"<<setiosflags(ios::fixed) << setprecision(2)<<dayDrillCost<<endl;
    dayCounter --;
}
cout<<"Drill completed";

}

  • 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-03T08:11:28+00:00Added an answer on June 3, 2026 at 8:11 am

    This is a simple loop that increments a single counter three times. From this, you can see hoe to generalize it for all your counters.

    int someCounter = 0;
    
    for (int day=0; day<3; ++day) { // loop three times
    
      // do your cin input here
      int tmp;
      cin >> tmp;
      someCounter += tmp; // increment running total
    
    }
    
    // print the total
    

    If you have many counters, you may consider creating a struct or class holding these, defining operator+= for that class, and overriding istream operator>> for that class, but I get a feeling that may go beyond what is expected from your assignment. In any case, there are plenty of questions on SO explaining how to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.