功能
用到的觀念
CODE
/*PROGRAMMER :楊翔斌*/
/*DATE :2009-10-08*/
/*FILENAME :HW01A002.cpp*/
/*DESCRIPTION:use different way to show the number*/
#include<iostream>//標頭檔
#include<iomanip>
#include<cmath>
using namespace std;
using std::setw;
using std::fixed;
using std::setprecision;
int main()
{
int b,ch;//宣告變數為int,ch為選擇的選項
double a,c,n,j;//宣告變數為double
cout<<"type 1 you can enter the digit and the number you want, type 2 you can
only type number: ";
cin>>ch;
while(ch!=1&&ch!=2){//if ch is not equal to 1 and 2, it'll show the wrong
message
cout<<"you type the wrong number, please type again: ";
cin>>ch;
}
if(ch==1)
{
cout<<"enter the the decimal you want "<<endl;//ask user for data
cout<<"the programme can deal the number under 16 decimals"<<endl;//describe
some rule
cin>>n;//read a number for decimal
cout<<"enter the the number "<<endl;//ask user for data
cin>>c;//read a number for the number
while(c<pow(10.0,n-1)||c>pow(10.0,n))//check whether the number is right
{
cout<<"invalid"<<endl;//tell the user the number is invalid
cout<<"please enter the right number again"<<endl;//ask user to type again
cin>>c;//read the number
}
}
if(ch==2)
{
double x;//declare x to store some number
cout<<"enter the the number "<<endl;//ask user for data
cin>>c;
x=log10(c);
n=int(x+1);
}
for(j=1;j<=n;j++)//loop for n times
{
if(j!=n)//check if j is equal to n
{b=int(c/pow(10.0,n-j));//calculate
a=c-b*pow(10.0,n-j);//calculate use it as mod
cout<<b<<"$$$";//show the symbol
c=a;//a is save into c
}
if(j==n)//check if j is equal to n
{
cout<<c;//show the number
}
}
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.7.59