Hi,guys.my girlfriend give me this question,please any one to help me on how to start.
1.Write a program to compute the rate of growth,expressed as % of an
insect population,take as input the initial size of the population and
its size,one week later,then compute the rate of growth and predict
the size of populate in yet another weeks,assuming that growth
continous at the same rate.
/*===================For Sweetie of Mine======================*/
#include<iostream>
usingnamespace std;
int main() {
//Tuna declare variable zote hapa kwanza
int population = 100;
int populationSize = 200;
int weeks;
int rate;
int ratePercent;
//Part One==============
//Here program will calculate rate% of growth
rate=populationSize-population;
ratePercent=(rate/populationSize)*100;
cout<<"Rate in % of growth is: "<<ratePercent<<"%"<<endl;
//Part two==============
//Process
cout<<"For how many weeks you need to predict population?"<<endl;
cin>>weeks;
int size_for_weeks=(rate*weeks)+population;
//The calculation was easy because growing rate was the same for any week. ref.QTN
cout<<"The size will be " <<size_for_weeks<<" insects for "<<weeks<<endl;
//Futa 'system("PAUSE")' kama unatumia codeBlock
system("PAUSE");
return 0;
}
Don't forget you can add your own debug output (or use a debugger) to help you trace through the program and find the problem areas. Divide and conquer.
i'd still say you have to convert your ints into floats/doubles...
what if the rate is something like 1 and the populationsize is 3? you'd get a decimal number,
which would automatically be converted into an integer. In this example that wouldn't happen (since .33 is rounded downwards), but with other examples that could give wrong results :)