Help with Switch & Calculation Sets

Can anyone tell me how to use a statement, maybe switch, to change the used block of code of calculation for a specific gender. I'm calculating body fat for both males and females and they use different equation to measure their fat


Basically what I think I am trying to do is, have the user input whether or not the one to be calculated is a female or male and calculate the body fat using specific statements (equations depending on the gender input).

Can I just declare char M & F and make a code like switch (m or f) ( I forget if there is an operator for "or" maybe it's "||"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  
// This program will use for loops and 
// switch staements to determine measure
// the body fat of either a male or female

//To Do:
// 1: Ask Name
// 2: Determine Gender
// 3: Input Weight & Measurements
// 4: Calculate Fat Percentages
// 5: Repeat Loop ( Well actuallty first thing to do)


// Step 0: Housekeeping
#include <iostream>
using namespace std;
#include <string>
int main()

{
	// Step 1: Declarations 
	string name1, name2, gender;
	int A1; // [BOTH][Women] (body weight x 0.732) + 8.987 -- [Men] (body weight x 1.082) + 94.42
	int A2; // [BOTH][Women] wrist measurement 9 at (fullest point) -- [Men] wrist measurement x 4.15
	int A3; // [Women ONLY] waist measurment (at navel) x 0.157
	int A4; // [Women ONLY] hip measuremnt  (at fullest point) x 0.434
	int A5; // [Women ONLY] forearm measurement (at fullest point) x 0.434

	int B;  // "B" (stands for body perhaps?) -- [Women] B = A1 + A2 - A3 - A4 + A5 -- [Men] B = A1 - A2

	int BodyFat;            // [BOTH] Body fat = body weight - B 
	int BodyFatPercnetage;  // [BOTH] Body fat percentage = body fat x 100 / body weight 

	// Step 2: For Loop
	int i;					// Declared to be used with for loop
	for (i = 0; i < 5; i++) // for loop

		// Step 3: Start of Loop Statements & User Input
	{
		cout << "Enter the first and last name of the person to measure body fat of." << endl;
		cin >> name1, name2;
		cout << "Enter M or F, if person is male or female." << endl;

	}






	// Step 4: End of For loop & Final Step - Ending Program

	return 0;


}



Anyway any help or input would be appreciated and thank you
你不是一下子输入这些信息,然后循环啊
Try using an if else statement for specifying the gender .
example


if(condition) //condition for a male or female
{

}
else // This will loop on the opposite of the former
{

}

Also try using float instead of int with A1,A2 .... because your calculations will be in a decimal form.
Sorry but I am trying to do it using switch, I hate that I have to though.
Topic archived. No new replies allowed.