user975452
user975452

Reputation: 11

track how many times an if statement was used true

I think the question speaks for itself, I'm writing a program in c++ and there is a part where the console asks the user which type of input they want to use

while (loop == 5) {
  cout << "\nWould you like to enter a depoist or a check? "; //asks for a choice
  cin >> choice;
  //determines whether or not to close the program
  if(choice == 0 || depo == 0 || check == 0) {
    return 0;          
  }//end close if
  //choses which type of input to make
  if( choice == 1) {
    cout << "\nPlease enter check amount: ";    
    cin >> check;
    check += check;
  } else if(choice == 2) {
    cout << "\nPlease enter deposit amount: ";
    cin >> depo;
    depo += depo;
  }//end if
}

but how do i keep track of how many times the if statement was true?

Upvotes: 0

Views: 191

Answers (1)

Mysticial
Mysticial

Reputation: 471489

You can add a counter and increment it every time you enter the if-statement's true block.

int true_counts = 0;
while (loop == 5){

    ...

    if( choice == 1){
        true_counts++;

    ...

Upvotes: 3

Related Questions