首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

HELP,该怎么解决

2014-01-03 
HELPDescriptionThe monthly salary of a person is increased by a fixed percentage every year. With t

HELP
Description
The monthly salary of a person is increased by a fixed percentage every year. With the current salary and target amount given, please calculate how many years are needed to reach or just exceed the target.
Input
There are multiple test cases. Each line contains one case (three integers).
The first number in a line is the current monthly salary, the second number is the percentage of increase per year and the third one is the target amount.
The initial monthly salary is no less than 100 and it is always an integral value even after the increase every year. For example, the number 160 will change to be 164 after increase by 3%. The percentage is a number no less than 1. The target amount is no more than 1000000.
The line with “0 0 0” implies the end of input.
Output
For each test case, print out in a single line the number of years needed, in integer.
Sample Input
300 5 10000
120 1 150000
0 0 0
Sample Output
3
79

My Code
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int s,p,t;
    double y=0.0;
    int account=0; 
    while(cin>>s>>p>>t)
    {   
        if(s==0&&p==0&&t==0)
        break;
        else
        {
        while(y<t)
        {
             y+=12.0*s;
     s=floor(s*(1.0+p/100.0));
             account++;   
        }
cout<<account<<endl;
        }
    }
    return 0; 
}
What's wrong?
[解决办法]

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int s,p,t;
    double y=0.0;
    int account=0; 
    while(cin>>s>>p>>t)
    {  
        //if(s==0&&p==0&&t==0)
        if(s<100
[解决办法]
p<1
[解决办法]
t>1000000)//I think it should be like this.
        {
            break;
        }
        else
        {
            //This is a loop,so you need clear y and account before loop.           
            y = 0.0;
            account =0;
            while(y<t)
            {
                y+=12.0*s;
                //s=floor(s*(1.0+p/100.0));


                s=int(s*(1.0+p/100.0));
                account++;   
            }
            cout<<account<<endl;
        }
    }
    return 0; 
}


My English is too poor to state more detail.Sorry!

热点排行