69,375
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
const double FIRST = -0.3; // 第一个数字
const double END = 0.3; //第二个数字
int main()
{
double input = 0;
cout << "Please input a number between " << FIRST << " and " << END << ":" << endl;
cin >> input;
if(input < -0.3 || input > 0.3) // 检查所输入数据是否在规定的范围
{
cout << "A wrong number entered...try again..." << endl;
exit(0);
}
cout << "The percentage is:" << endl;
cout << (input - FIRST)/(END - FIRST) * 100 << "%" << endl;
return 0;
}
#include <iostream>
const double FIRST = -0.3; // 第一个数
const double END = 0.3; // 第二个数
int main()
{
double input = 0;
cout << "Please input a number between " << FIRST << " and " << END << ":" << endl;
cin >> input;
if(input < -0.3 || input > 0.3) // 检查所输入数据是否在规定的范围
{
cout << "A wrong number entered...try again..." << endl;
exit(0);
}
cout << "The percentage is:" << endl;
cout << (input - FIRST)/(END - FIRST) * 100 << "%" << endl;
return 0;
}
int main(void)
{
float lower = -0.5000;
float upper = 1.5000;
float current = 1.0000;
if(lower >= upper || current < lower)
{
printf("Invalid\n");
return -1;
}
int answer = 100 * (current - lower) / (upper - lower);
printf("%d%%\n", answer);
return 0;
}