c++ - How can I change my program by using a summing statement instead? -


my c++ assignment write program display population estimate of each of countries (mexico , us) year, 1985 present. round population nearest whole number , display information in 3 columns. after doing that, modify program display same information when mexico's population exceeds population. did program correctly, when ran it gave me correct information , professor gave me 0 credit because wants me not use pow function summing statement, don't know how can that, sounds more complicated me. program wrote way don't know how change using summing statement:

//program compute when mexico's pop exceeds pop #include<iostream> #include<cmath> #include<iomanip> using namespace std; int main() {     int years;     double uspop, mxpop;     cout<<setw(7)<<"year"<<setw(13)<<"us pop"<<setw(13)<<"mex pop"<<endl;     cout<<setprecision(0)<<fixed;     for(years=1985;years<=2014;years++)     {         uspop=243000000.0*(pow(1.007,(years-1984)));         mxpop=78000000*pow(1.033,(years-1984));         cout<<setw(7)<<years<<setw(13)<<uspop<<setw(13)<<mxpop<<endl;     } } 

i not sure mean "summing statement", since doesn't problem needs "+" operation.

in case don't have use pow, can overwrite , mex population number @ each iteration multiply using indicator.

below example:

int main() {     int years;     double uspop=243000000.0;     double mxpop=78000000;     cout<<setw(7)<<"year"<<setw(13)<<"us pop"<<setw(13)<<"mex pop"<<endl;     cout<<setprecision(0)<<fixed;     double usindicator = 1.007;     double mexindicator = 1.033;      for(years=1985;years<=2014;years++)     {         uspop=uspop*usindicator;         mxpop=mxpop*mexindicator;         cout<<setw(7)<<years<<setw(13)<<uspop<<setw(13)<<mxpop<<endl;     } } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -