Loops in my project.

I need at least one loop in my project. My knowledge of loops seems to not all be there yet. When I run my code right now the loop runs on and on. Both do not work right now in my code. Any advice or help will be much thanked!

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
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;

main ()
{
        //declarations
        char gender; //what gender is the user
        double weight; //weight in pounds
        double age; //age in years
        double height; //height in inches
        double bmr; //total calories you can consume
        double cb; //calories of chocolate bars
        double total; //total number of cookies that can be consumed
        char answer; //answer to question about excerise
        double exercise; //amount of exercise you get as a percent
        double ncb; //new amount of chocolate bars you can eat

        //inputs
        cb = 230;
        cout << "How many chocolate bars can you eat?\n";
        cout << "Welcome, first we need your age.\n";
        cin >> age;
        cout << "Next your weight in pounds.\n";
        cin >> weight;
        cout << "Now your height in inches.\n";
        cin >> height;
        cout << "How much excerise do you get.\n";
        cout << "a. Sendentary.\n";
        cout << "b. Somewhat active (exercise occasionally).\n";
        cout << "d. Highly Active (exercise daily).\n";
        cin >> answer;

        do
        {
        if ((answer == 'a') || (answer == 'A'))
          exercise = 0.2;
        else if ((answer == 'b') || (answer == 'B'))
          exercise = 0.3;
        else if ((answer == 'c') || (answer == 'C'))
          exercise = 0.4;
        else ((answer == 'd') || (answer == 'D'));
         cout << "error.\n";
        } while ((answer == 'a') || (answer == 'A') || (answer == 'b') || (answer == 'c') || (answer == 'C') || (answer == 'B') || (answer == 'd') || (answer == 'D'));
        
        cout << "Finally your gender (M/F).\n";
        cin >> gender;

        do
        {
            if ((gender == 'M') || (gender == 'm'))
            {
                //processing
                bmr = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
                total = bmr * exercise;
                ncb = total / cb;
                cout << "The total amount of chocolates with exercise is ";
                cout << ncb;
            }
            else ((gender == 'F') || (gender == 'f'));
            {
                //processing
                bmr = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
                total =  bmr / cb;
            }
        } while ((gender == 'M') || (gender == 'm') || (gender == 'F') ||  (gender == 'f'));

}


Please note the code isn't completed, I would just like my loops to run properly. Thanks
Are you stuck in an infinite loop? My guess is that you want to loop the whole program and not the gender input.
I am stuck in an infinite loop. I would like the program to loop back to the question if the input was not one given. Like if you put in F instead of a letter through A-D, or for the gender one too.
You put the inputs outside the loop. Move them in.
put another cin >>answer inside your 1st do - while loop, below cout << "Error"; so that you can repeat the input if the answer doesn't meet the condition in while ()

Another thing:
1
2
else ((answer == 'd') || (answer == 'D'));
         cout << "error.\n";

i bet your're missing something here :/
You made d your third choice. You're going to confuse the user. To make your code a little bit easier for you, you could also use answer = tolower(answer);. This will put answer in lower case, so you only have to compare against lower case letters.
Topic archived. No new replies allowed.