- 分享
- 0
- 人气
- 0
- 主题
- 11
- 帖子
- 296
- UID
- 225210
- 积分
- 244
- 阅读权限
- 14
- 注册时间
- 2009-5-8
- 最后登录
- 2022-2-23
- 在线时间
- 2771 小时
|
我的code基本上是可以work了得
但是我要加array去,可以算几个人的BMI在同一时间,和可以选择measure unit (meter,inches)
但是这两个东西我写来写去弄不出来,
谁可以帮帮忙? TT- #include <iostream>
- using namespace std;
- void displayMenu()
- {
- cout << "*-------------------------------------*" << endl;
- cout << "| BMI Calculator |" << endl;
- cout << "|=====================================|" << endl;
- cout << "| Select: |" << endl;
- cout << "| 1 => Display Data |" << endl;
- cout << "| 2 => Insert Data |" << endl;
- cout << "|-------------------------------------|" << endl;
- cout << "| 3 => Calculate Standard BMI |" << endl;
- cout << "| 4 => Clear Data |" << endl;
- cout << "|-------------------------------------|" << endl;
- cout << "| Q => Quit |" << endl;
- cout << "*-------------------------------------*" << endl;
- cout << endl;
- cout << "Choice: ";
- }
- void DisplayData( string &name, float &weight, float &height,float &bmi )
- {
- cout << endl;
- cout << "Name = " <<name<< endl;
- cout << "Weight = " <<weight<< endl;
- cout << "Height = " <<height<< endl;
- cout << endl;
- }
- void InsertData( string &name, float &weight, float &height,float &bmi )
- {
- cout << endl;
- cout<<"Please Enter Your Name\n";
- cin >>name;
- cout <<"Enter your weight in Kilograms (KG) : ";
- cin >> weight;
- cout <<"\nEnter your height in Meters (M) : ";
- cin >> height;
-
- cout<<"You are now able to calculate your BMI."<<endl;
- }
- void Calculate( string &name, float &weight, float &height,float &bmi )
- {
-
- bmi = weight/(height*height);
- cout<<"Your BMI is: "<<bmi<<endl;
- if (bmi <= 18.5)
- cout << "You are under weight."<<endl;
- else if ((bmi > 18.5 ) && (bmi < 25))
- cout << "Your weight is in the normal range."<<endl;
- else if (bmi >= 25)
- cout << "You are overweight."<<endl;
-
-
-
-
-
- }
- void setPrecision ()
- {
- cout.setf(ios::fixed);
- cout.setf(ios::showpoint);
- cout.precision(1);
- }
- void DebugCalculator(string name, float weight, float height)
- {
- if(name == "null" && weight==0 && height ==0 )
- cout<<"Please Insert Your Data Before You Calculate Your BMI Or Your Data is Invalid."<<endl;
- }
- int main()
- {
- string name = "null";
- float weight = 0 ;
- float height = 0;
- char choice;
- bool invalid = true;
-
- do
- {
- float bmi;
- {
- displayMenu();
- cin >> choice;
- choice = toupper(choice);
- switch (choice)
- {
- case '1' : DisplayData(name, weight, height, bmi);
- break;
- case '2' : InsertData( name, weight, height, bmi);
- break;
- case '3' : DebugCalculator(name,weight,height);
- setPrecision();
- Calculate( name, weight, height, bmi);
- break;
- case '4' : DisplayData(name="null", weight=0,height=0,bmi);
- cout << "Your record have been deleted, please insert your data again." << endl;
- break;
- case 'Q' : invalid = false;
- cout<<"Thanks for using"<<endl;
- break;
- default : cout << "Invalid selection, try again!" << endl;
-
- }
- }
- }while(invalid);
- cout << "Good bye and have a nice day!" << endl;
- cout << endl;
- system("PAUSE");
- return 0;
- }
复制代码 |
|