Counting how many times variable has changed

Konrad

I have to write the program, when after terminating infinite while loop "while(cin>>a)" by, let's say "-1", program says me how many times value increased. For input "0 0 2 2 3 4 8 8 8 -1" it should print "4". First part isn't problem, but I have no idea how to count how many times it had changed over time. Any tips? Thanks a lot.

SilverS

You should use counters which will basically increase each time your value increases. Check the code bellow:

int value, highestValue, counter = 0, counter2 = 0;
do{
       cout << "Enter the value: ";
       cin >> value;
       if(counter2 == 0){
                    highestValue = value;
                  }
       if(value > highestValue){
                  counter++;
                  highestValue = value;
                }
       counter2++;
}while(value != -1);

cout << "The number increased " << counter << " times!\n";

The second counter (counter2) is required in the first if statement to store the first value you enter as the highest value.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Counting how many times my Android app has been opened

From Dev

Pandas counting how many times a value has been counted in a Group by

From Dev

Counting how many times the click() function has been used

From Dev

counting how many times a variable changes score by group

From Dev

Count how many times a certain value per user has changed

From Dev

Count how many times a value in the database has changed?

From Dev

Find how many times the department of an employee has changed

From Dev

Check how many times a file has been changed

From Dev

Count how many times values has changed in column using R

From Dev

How can I see how many times a username has appeared without counting manually

From Dev

Counting the number of times a value has changed within a cell

From Dev

Counting how many times a loop runs

From Dev

Counting how many times each vowel appears

From Dev

Counting how many times an image appears on screen

From Dev

How do I count how many times a value has changed pertaining to a unique ID?

From Dev

how to calculate how many times is changed in the column

From Dev

PromQL, Grafana - Count how many times metric's labels values has changed

From Java

How to detect if a variable has changed?

From Dev

Counting how many times the biggest number in a column appear in Excel

From Dev

Counting how many times each unique element appeared in `select` query

From Dev

Counting how many times each unique element appeared in the table

From Dev

Counting how many times there are blank lists in a list of list

From Dev

Counting how many times a character is typed without using string

From Dev

Counting how many times a specific checked value occurs in AngularJS

From Dev

Counting how many times a base function is being used, Python

From Dev

Python: counting how many times a given line is executed

From Dev

Counting how many times a boolean value changes in SQL Server

From Dev

Counting how many times a row occurs in a matrix (numpy)

From Dev

Counting how many times a function is called recursively (Python)

Related Related

  1. 1

    Counting how many times my Android app has been opened

  2. 2

    Pandas counting how many times a value has been counted in a Group by

  3. 3

    Counting how many times the click() function has been used

  4. 4

    counting how many times a variable changes score by group

  5. 5

    Count how many times a certain value per user has changed

  6. 6

    Count how many times a value in the database has changed?

  7. 7

    Find how many times the department of an employee has changed

  8. 8

    Check how many times a file has been changed

  9. 9

    Count how many times values has changed in column using R

  10. 10

    How can I see how many times a username has appeared without counting manually

  11. 11

    Counting the number of times a value has changed within a cell

  12. 12

    Counting how many times a loop runs

  13. 13

    Counting how many times each vowel appears

  14. 14

    Counting how many times an image appears on screen

  15. 15

    How do I count how many times a value has changed pertaining to a unique ID?

  16. 16

    how to calculate how many times is changed in the column

  17. 17

    PromQL, Grafana - Count how many times metric's labels values has changed

  18. 18

    How to detect if a variable has changed?

  19. 19

    Counting how many times the biggest number in a column appear in Excel

  20. 20

    Counting how many times each unique element appeared in `select` query

  21. 21

    Counting how many times each unique element appeared in the table

  22. 22

    Counting how many times there are blank lists in a list of list

  23. 23

    Counting how many times a character is typed without using string

  24. 24

    Counting how many times a specific checked value occurs in AngularJS

  25. 25

    Counting how many times a base function is being used, Python

  26. 26

    Python: counting how many times a given line is executed

  27. 27

    Counting how many times a boolean value changes in SQL Server

  28. 28

    Counting how many times a row occurs in a matrix (numpy)

  29. 29

    Counting how many times a function is called recursively (Python)

HotTag

Archive