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 6950129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:03:18+00:00 2026-05-27T14:03:18+00:00

I’m almost done with this program, but something’s not right in main . Here

  • 0

I’m almost done with this program, but something’s not right in main. Here are the project instructions:

Assignment:
Write a program which keeps track of the number of roaches in two adjacent houses for a number of weeks. The count of the roaches in the houses will be determined by the following:

  1. The initial count of roaches for each house is a random number between 10 and 100.
  2. Each week, the number of roaches increases by 30%.
  3. The two houses share a wall, through which the roaches may migrate from one to the other. In a given week, if one house has more roaches than the other, roaches from the house with the higher population migrate to the house with the lower population. Specifically, 30% of the difference (rounded down) in population migrates.
  4. Every four weeks, one of the houses is visited by an exterminator, resulting in a 90% reduction (rounded down) in the number of roaches in that house.

Here’s my code:

#include <iostream>
#include <cmath>
using namespace std;

int house, increase, roaches, filthyBeasts; // My variables for my four functions
int initialCount(int house);
int weeklyIncrease(int increase);
int roachesMigration(int more, int fewer, int change);
int exterminationTime (int filthyBeasts);
// My four function prototypes 

int main()
{
    int houseA, houseB;

    houseA = initialCount(houseA); //Initializing the inital count of House A.
    houseB = initialCount(houseB); //Initializing the inital count of House B.

    int week = 0;
    for (week = 0; week < 11; week++) // My for loop iterating up to 11 weeks.
    {
        houseA = weeklyIncrease(houseA);
        houseB = weeklyIncrease(houseB);

        cout << "For week " << week << ", the total number of roaches in House A is " << houseA << endl;
        cout << "For week " << week << ", the total number of roaches in House B is " << houseB << endl;

        if((houseA > houseB)) // Migration option 1
        {
            houseB = roachesMigration(houseA, houseB);
        }
        else if((houseB > houseA)) // Migration option 2
        {
            houseA = roachesMigration(houseA, houseB);
        }


        if ((week + 1) % 4 == 0) // It's extermination time!
        {
            if ((rand() % 2) == 0) // Get a random number between 0 and 1.
            {
                houseB = exterminationTime(houseB);
            }
            else
            {
                houseA = exterminationTime(houseA);                   
            }
        }
    }

    return 0;
}

int initialCount(int house) // Initializing both houses to random numbers between 10 and 100.
{
    int num;
    num = (rand() % 91) + 10;
    return num;
}

int weeklyIncrease(int increaseHouses) // Increasing the roaches in both houses by 30% weekly.
{
    int increase = 0;
    increase = (increaseHouses * .3) + increaseHouses;
    return increase;
}

int roachesMigration(int more, int fewer, int change)
{
    more -= change;
    fewer += change;   
    return ((more - fewer) * .3);
}


int exterminationTime(int filthyBeasts) // Getting rid of the filthy little beasts!
{
    filthyBeasts = (filthyBeasts * .1);
    return filthyBeasts;
}

There are issues with the migration and extermination functions. I’m receiving an error message from the compiler that says, “error: Semantic Issue: No matching function for call to ‘roachesMigration'”. Also, at weeks 4 and 8, the randomly selected house should get exterminated, and the number of roaches in that house should be 90% less than the previous week. What do you guys think I should do to correct this issues? I really appreciate all help!

  • 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-05-27T14:03:19+00:00Added an answer on May 27, 2026 at 2:03 pm

    Hint: I notice that you’re printing the value of week out at the end of your for loop. In other words, your output should be something like:

    For week 0, the total number of roaches in House A is 4
    For week 0, the total number of roaches in House B is 5
    0
    For week 1, the total number of roaches in House A is 6
    For week 1, the total number of roaches in House B is 7
    1
    

    However, I suspect that the weeks being printed are not what they should be.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but

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.