VC++ 遇到一个棘手的问题 请教
来源:百度知道 编辑:UC知道 时间:2024/05/18 03:40:42
这个题目百度知道上也有人提出来,不过参考了他的程序,我发现结果还是不对!! 请高手指点下!
我写的程序如下:
// Doforni.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "math.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int HUGE_DOFORNI=50;
const int BIG_DOFORNI=20;
const int MINDDLE_DOFORNI=5;
const int SMALL_DOFORNI=1;
int hugeNumber;
int bigNumber;
int middleNumber;
int smallNumber;
cout << "\nPlease enter the totle doforni number: ";
int totDoforniNum;
cin >> totDoforniNum;
hugeNumber = totDoforniNum/HUGE_DOFORNI;
bigNumber = totDoforniNum/HUGE_DOFORNI%BIG_DOFORNI;
middleNumber = (totDoforniNum/HUGE_DOFORNI%BIG_DOFORNI)%MINDDLE_DOFORNI;
smallNumber
代码修正后如下。
// Doforni.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "math.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int HUGE_DOFORNI=50;
const int BIG_DOFORNI=20;
const int MINDDLE_DOFORNI=5;
const int SMALL_DOFORNI=1;
int i;
int hugeNumber;
int bigNumber;
int middleNumber;
int smallNumber;
cout << "\nPlease enter the totle doforni number: ";
int totDoforniNum;
cin >> totDoforniNum;
hugeNumber = totDoforniNum/HUGE_DOFORNI;
bigNumber = totDoforniNum%HUGE_DOFORNI/BIG_DOFORNI; //从本行起连续3行错误,已经改正
middleNumber = (totDoforniNum%HUGE_DOFORNI%BIG_DOFORNI)/MINDDLE_DOFORNI;
smallNumber = ((totDoforniNum%HUGE_DOFORNI%BIG_DOFORNI)%MINDDLE_DOFORNI)/SMALL_DOFORNI;
cout << "\nThe huge doforni number is: " <<