Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用求和语句来更改程序? 我的C++任务是编写一个程序,显示每个国家(墨西哥和美国)的人口估计,从1985到现在。将总体四舍五入到最接近的整数,并在三列中显示信息。这样做之后,我要修改程序,让它在墨西哥人口超过美国人口之前显示相同的信息。我正确地做了这个程序,当我运行它时,它给了我正确的信息,除了我的教授之外,所有人都给了我0分,因为他希望我不要使用POW函数,而是一个求和语句,我不知道我怎么做,这对我来说听起来更复杂。这是我写的程序,我只是不知道如何使用summing语句来更改它: //Program to compute when Mexico's pop exceeds the US 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; } } //墨西哥流行音乐超过美国流行音乐时的计算程序 #包括 #包括 #包括 使用名称空间std; int main() { 整数年; 双UsPop,MxPop; 我不知道你所说的“求和语句”是什么意思,因为你的问题看起来不需要“+”运算_C++_For Loop_Sum - Fatal编程技术网

如何使用求和语句来更改程序? 我的C++任务是编写一个程序,显示每个国家(墨西哥和美国)的人口估计,从1985到现在。将总体四舍五入到最接近的整数,并在三列中显示信息。这样做之后,我要修改程序,让它在墨西哥人口超过美国人口之前显示相同的信息。我正确地做了这个程序,当我运行它时,它给了我正确的信息,除了我的教授之外,所有人都给了我0分,因为他希望我不要使用POW函数,而是一个求和语句,我不知道我怎么做,这对我来说听起来更复杂。这是我写的程序,我只是不知道如何使用summing语句来更改它: //Program to compute when Mexico's pop exceeds the US 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; } } //墨西哥流行音乐超过美国流行音乐时的计算程序 #包括 #包括 #包括 使用名称空间std; int main() { 整数年; 双UsPop,MxPop; 我不知道你所说的“求和语句”是什么意思,因为你的问题看起来不需要“+”运算

如何使用求和语句来更改程序? 我的C++任务是编写一个程序,显示每个国家(墨西哥和美国)的人口估计,从1985到现在。将总体四舍五入到最接近的整数,并在三列中显示信息。这样做之后,我要修改程序,让它在墨西哥人口超过美国人口之前显示相同的信息。我正确地做了这个程序,当我运行它时,它给了我正确的信息,除了我的教授之外,所有人都给了我0分,因为他希望我不要使用POW函数,而是一个求和语句,我不知道我怎么做,这对我来说听起来更复杂。这是我写的程序,我只是不知道如何使用summing语句来更改它: //Program to compute when Mexico's pop exceeds the US 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; } } //墨西哥流行音乐超过美国流行音乐时的计算程序 #包括 #包括 #包括 使用名称空间std; int main() { 整数年; 双UsPop,MxPop; 我不知道你所说的“求和语句”是什么意思,因为你的问题看起来不需要“+”运算,c++,for-loop,sum,C++,For Loop,Sum,在任何情况下,您都不必使用pow,只需在每次迭代时覆盖US和Mex人口数,然后使用指示符进行乘法即可 下面是一个例子: int main() { int Years; double UsPop=243000000.0; double MxPop=78000000; cout<<setw(7)<<"Year"<<setw(13)<<"US Pop"<<setw(13)<<"Mex Pop"<

在任何情况下,您都不必使用
pow
,只需在每次迭代时覆盖US和Mex人口数,然后使用指示符进行乘法即可

下面是一个例子:

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;
    }
}
intmain()
{
整数年;
双UsPop=243000000.0;
双MxPop=78000000;

难道你的教授希望你编写自己的Pow函数,而不是使用数学库中的函数吗?你可以尝试替换你的:

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;
}
什么是“求和语句”?
for (Years = 1985; Years <= 2014; Years++)
{
             UsPop = 243000000.0 * (myPow((Years - 1985), 1.007));
             MxPop = 78000000 * (myPow((Years - 1985), 1.033));
}
    double myPow(double flag, double number)
    {
        double pow = number;
        //You can edit my formula to match "summing statement" as  your professor require .
        for (int i = 0; i < flag; i++)
        {
            pow *= number; //If I'm not mistaken, you should split it up to "Plus" then you will get your "summing statement".
        }
        return pow;
    }
1) 299564530.595318/206587599.027265
---------------------------
2) 299564530.595318/206587599.027265