# Thread: compare to pervious values

1. ## compare to pervious values

How can I compare a previous value with a current value to analysis the input of each day with a while loop?
The input's times are defined by the user; as "printf("Enter the number in day %d: ", days); scanf("%d", &number)

I want to set a current day = previous day outside the while loop, but how to compare in the loop again each time?

This program is ok, except the twice value.

Code:
```/*  Purpose of this program: Analytics of clicking on a web-based
*/

#include <stdio.h>

int main() {

int days; /* with days++ in looping to count the input days */
int daysPeriod; /* Input the days are needed to analytics */
int highest; /* Highest value  */
int lowest; /*Lowest value */
int more500; /* Click more than 500 */
int click; /* number of click each loop */
int sumClick; /* Total click value */
int twice; /* count the clicks that more than twice for previouse day */
int currentday, hold;

/*initialize vlaue*/
click =0;
highest=0;
lowest=2.e2; /* let the lowest to be max value for easy to compare the input value. */
twice = 0;
hold = 0;
currentday = 0;
sumClick = 0;
days = 1;

/* Read how many days are need to analytis */
printf("Enter the period of click analytics (number of days): ");
scanf("%d", &daysPeriod);

/* Using a while loop to count the input day for analytics, the input day at lease is 1 day. */
while (days <= daysPeriod) {

/* Read how many clicks per day within while loop for daysPeriod, as input's day. */
printf("Enter the clicks in day %d: ", days);
scanf("%d", &click);
fflush(stdin);

hold = click; /*unused*/

/* Checking the value of click is value highest or lowest */
if (click > highest)
{
highest = click;}

if (click < lowest){
lowest = click;}

/* Checking the value of click, if over 500 times, the value of more500 will be counted. */
if(click >= 500)
{
more500++;
}

/* Checking the value of currentday, if the click of pervious day is more then current day 2 times,
the value of twice will be counted */
if(currentday/2 < click)
{
currentday = click;
twice++;
}

/* Add the total click's value each loop, then put it into sum of click, as sumClick */
sumClick += click;

/* This days will be added each loop until all input's days are counted; as days will be equal to dayPeriod. */
days++;
}

/* printout the click's results of average, highest, lowest, click more than 500 and clicks twice more than the previous day. */

printf("Average click is: \$%d\n", sumClick / daysPeriod);
printf("Highest clicks is %d\n", highest);
printf("Lowest clicks is %d\n", lowest);
printf("Number of days with clicks more than 500 is %d\n", more500);
printf("Number of days with clicks twice of previous day: %d\n", twice);

return 0;
}```

2. A better indentation style would help.
Indentation style - Wikipedia

Like so
Code:
```/*  Purpose of this program: Analytics of clicking on a web-based
*/
#include <stdio.h>

int main()
{
int days;                     /* with days++ in looping to count the input days */
int daysPeriod;               /* Input the days are needed to analytics */
int highest;                  /* Highest value  */
int lowest;                   /*Lowest value */
int more500;                  /* Click more than 500 */
int click;                    /* number of click each loop */
int sumClick;                 /* Total click value */
int twice;                    /* count the clicks that more than twice for previouse day */
int currentday, hold;

/*initialize vlaue */
click = 0;
highest = 0;
lowest = 2.e2;                /* let the lowest to be max value for easy to compare the input value. */
twice = 0;
hold = 0;
currentday = 0;
sumClick = 0;
days = 1;

/* Read how many days are need to analytis */
printf("Enter the period of click analytics (number of days): ");
scanf("%d", &daysPeriod);

/* Using a while loop to count the input day for analytics, the input day at lease is 1 day. */
while (days <= daysPeriod) {
/* Read how many clicks per day within while loop for daysPeriod, as input's day. */
printf("Enter the clicks in day %d: ", days);
scanf("%d", &click);

hold = click;               /*unused */

/* Checking the value of click is value highest or lowest */
if (click > highest) {
highest = click;
}
if (click < lowest) {
lowest = click;
}

/* Checking the value of click, if over 500 times, the value of more500 will be counted. */
if (click >= 500) {
more500++;
}

/* Checking the value of currentday, if the click of pervious day is more then current day 2 times,
the value of twice will be counted */
if (currentday / 2 < click) {
currentday = click;
twice++;
}

/* Add the total click's value each loop, then put it into sum of click, as sumClick */
sumClick += click;

/* This days will be added each loop until all input's days are counted; as days will be equal to dayPeriod. */
days++;
}

/* printout the click's results of average, highest, lowest, click more than 500 and clicks twice more than the previous day. */
printf("Average click is: \$%d\n", sumClick / daysPeriod);
printf("Highest clicks is %d\n", highest);
printf("Lowest clicks is %d\n", lowest);
printf("Number of days with clicks more than 500 is %d\n", more500);
printf("Number of days with clicks twice of previous day: %d\n", twice);

return 0;
}```

Code:
```    /* Checking the value of currentday, if the click of pervious day is more then current day 2 times,
the value of twice will be counted */
if (currentday / 2 < click) {
currentday = click;
twice++;
}```
Better variable names would help.
Code:
```    if (yesterdayClicks / 2 < todaysClicks) {
yesterdayClicks = todaysClicks;
twice++;
}```

Popular pages Recent additions