Hello, can someone please help me with my code. I'm working on a program to calculate the monthly cost for excess minutes from two different cell phone companies. I still have a lot more to add to my code, but I am stuck on this particular part. I am reading from a .dat file call cell.dat and this is what it contains

``````2      32
3      45
1      36
3      15
1      30
1      32
2      29
5      59``````

And this is my code:

``````/* File: cell.c *  * Team: TCC
*  *  *   * Date: February 18, 2010 */

/* Two cell phone companies provide the same amount of free minutes and charge differently for excess minutes. This program calculates the cost of excess
*  * mi
*   * nutes per month for
*    *  *  * each cell phone company. */

#include <stdio.h>

/* Function declarations */
int JOG_minutes(float minutes);
int HOLO_minutes(float minutes);

main()
{ /* Declarations */
float min; /* Input for minutes */
float sec; /* Input for seconds */
float input; /* Input of minutes & seconds */
float excess_min; /* minutes + seconds */
int JOG_min; /* rounded JOG minutues invoked by function */
int JOG_min_total;
int HOLO_min_total;
int HOLO_min; /* rounded HOLO minutes invoked by function */
float cost_JOG; /* monthly cost with JOG */
float cost_HOLO; /* monthly cost with HOLO */

/* Obtain input for minutes & seconds */
printf("Please enter the excess amount of time.\n");
printf("Enter minutes, seconds: ");
input = scanf("%f %f", &min, &sec);

/* Service provider - Jog
*  *  * 1) Round each call to the nearest minute
*   *   * 2) Sum all rounded calls */

while (input != EOF)
{
/* Converts input into decimal form */
if ( sec > 9 ) /* When seconds is more than one digit */

{ excess_min = (min) + (sec * 0.01); }

else /* When seconds is only one digit */

{ excess_min = (min) + (sec * 0.1); }

printf("excess minutes = %f\n", excess_min);

/* Invoke function to round of each line of input */
JOG_min = JOG_minutes(excess_min);
printf("rounded excess minutes = %d\n", JOG_min);

/* Update loop */
printf("Enter minutes, seconds: ");
input = scanf("%f %f", &min, &sec);

/* Sum all rounded calls */
JOG_min_total = JOG_min + JOG_min_total;
printf("The total of all rounded minutes is %d minutes\n", JOG_min_total);

}

} /* End main */

int JOG_minutes(float minutes)

/* Given: Excess minutes
*  *  *
*   *   *    Returns: Excess minutes rounded to the nearest minute */

{

int value;
value = minutes + 1.0;
return value;
}``````

I want to have all the rounded values for the excess minutes to be added together, but I am coming up with very large number when I run the program with a.out < cell.dat .
Could someone please help me? I know it's something in my while loop, but I just can't seem to figure it out.

The variables you are using are all locally defined for the main function. The value that a local variable starts with when running the program is undefined. You need to make sure you initialize them to some known value (in this case, you should set them all to zero) before trying to use them, or you'll get nonsense values.

Since this is the earlier first post, I will assume this is the thread you don't need.

Do not post the same question by creating new threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.