精華區beta NTUCH-HW 關於我們 聯絡資訊
功能 用到的觀念 convert the character CODE #include"iostream"//標頭檔 #include"iomanip" #include"cmath" using namespace std; using std::setw; using std::fixed; using std::setprecision; int main() { int i=0,range=0,range1=0;//declare int variable. a=97 means it's a in char char word,choice,choice1,enter;//declare char variable. word is used to store character do{ do{ cout<<"please enter a beginning character(in small letter)"<<endl;//顯示內 容 cin>>choice;//輸入存到choice cout<<"please enter the last character(in small letter)"<<endl;//顯示內容 cin>>choice1; range=choice;//the content of choice appoint to range range1=choice1; if(range>=range1)//determine whether it type wrong { cout<<"you type wrong"<<endl; } }while(range>=range1); cout<<"character"<<setw(10)<<"decimal"<<setw(8)<<"octal"<<setw(10)<<left<<" hexadecimal value"<<endl; for(i=range;i<range1+1;i++)//run the loop { word=i;//i appoint to word in decimal cout<<word<<right<<setw(13)<<dec<<i<<setw(11)<<oct<<i<<setw(5)<<hex<<i<<endl;//using //different way to display the number } cout<<"do you want to enter again enter y or Y to continue or type e to laeve"<<endl; cin>>enter; if(enter=='e'&&enter=='E') { break; } else { while(enter!='Y'&&enter!='y'&&enter!='e'&&enter!='E') { cout<<"you type wrong"<<endl; cin>>enter; } } }while(enter!='e'&&enter!='E'); system("pause"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.7.59