Boolean Flag??

Hi, may I know how to implement the proceed as a Boolean flag? I not really know what is Boolean flag means, can anyone explain? Thanks...

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
#include <iostream>
#include <conio>

int main ()
{

	int proceed=1, itemCnt=0;
   	double price, totalPrice=0;
   cout<<"Program To Calculate The Average and Total Price Of Items \n\n";

   while (proceed==1)
   {
   	cout<<"Enter price of item: ";
      cin>>price;
      totalPrice += price;
      itemCnt++;
      cout<<"Anymore item? Enter 1 for yes OR 0 for no: ";
      cin>>proceed;
   }

   cout<<"\n\nYou have "<<itemCnt<< " Items";
   cout<<"\nThe Average Price Of The Items Is "<<totalPrice/itemCnt;
   cout<<"\nThe Total Price of the Items Is "<<totalPrice;
   cout<<"\nEnd of Program";

getch ();
return 0;
}
a boolean flag is a variable that get the value of either true or false, and nothing else. You can do it like this:
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
#include <iostream>
using namespace std;
int main ()
{

    bool proceed = true;
    int itemCnt=0;
    double price, totalPrice=0;
    cout<<"Program To Calculate The Average and Total Price Of Items \n\n";

    while (proceed)
    {
        cout<<"Enter price of item: ";
        cin>>price;
        totalPrice += price;
        itemCnt++;
        cout<<"Anymore item? Enter 1 for yes OR 0 for no: ";
        cin>>proceed;
    }

    cout<<"\n\nYou have "<<itemCnt<< " Items";
    cout<<"\nThe Average Price Of The Items Is "<<totalPrice/itemCnt;
    cout<<"\nThe Total Price of the Items Is "<<totalPrice;
    cout<<"\nEnd of Program";
    return 0;
}
Thanks yasar, means that if I enter "1", it will consider as "true" and "0" as false right base on the bool proceed = true; right?

How if I want to make it proceed when I enter "0"? Is that change to bool proceed = false? or how? TQ...
Topic archived. No new replies allowed.