I'm having a lot of issues with a program I'm working on and I really use any suggestions I could get. The purpose of the program is to take an input file that has a users name, the number of minutes in their call plan, and the number of minutes they actually used the month before. The programs calls for assigning a bonus number of minutes for the new month based on minutes used, and to output the name, minutes in plan, and amount of minutes for the new month. At the end it calls for the outputting of summary info; number of people with each call hour plan, total number of bonus hours awarded, average number of hours per user, and what i really need help with

the maximum and minimum number of hours used by the users

this is the first time I've tried using the set spaced char variable .. so im not sure if thats throwing off my inputs and outputs

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

//definition of the variables for the program
ifstream infile;
ofstream outfile;
char name[15];
int planmin, usedmin, fivecount, thoucount, twothoucount, bonustotal, bonusmin, quotamin, quotatot, mintotal, users; 
float average;

fivecount = 0;
thoucount = 0;
twothoucount = 0;
bonusmin = 0;
users = 0;
mintotal = 0;
bonustotal = 0;

     //opening of the input and putput files
     if (infile.fail())
         cout << "The input file cannot be located" << endl;
     outfile.open("file_customer.out", ios::out);
     if (outfile.fail())
         cout << "The output file could not be created" << endl;
       outfile << fixed << setprecision(0);
       //while loop to read the  
             infile.getline(name, 15) >> planmin >> usedmin;
             if (usedmin > 2000)
                bonusmin = (planmin * 0.15);
                else if (usedmin >= 1500 || usedmin <= 2000)
                   bonusmin = (planmin * 0.12);
                   else if (usedmin > 500 || usedmin < 1500)
                      bonusmin = (planmin * 0.10);
                       else if (usedmin == 500)
                          bonusmin = 1000;
              if (planmin == 500)
                 else if (planmin == 1000)
                       else if (planmin == 2000)
              quotamin = planmin + bonusmin;
              quotatot+= quotamin;
              mintotal+= usedmin;
              outfile << name << setw(8) << planmin << setw(8)<< quotamin << endl;
            average = mintotal / users;      
            outfile << endl;
            outfile << "Number of 500 minute plans  " << fivecount << endl;
            outfile << "Number of 1000 minute plans " << thoucount << endl;
            outfile << "Number of 2000 minute plans " << twothoucount << endl;
            outfile << "Maximum number of minutes by a user " << endl;
            outfile << "Minimum number of minutes by a user " << endl;
            outfile << "Average minutes used ber user " << average << endl;
            outfile << "Total Bonus Minutes given " << bonustotal << endl;
  return 0;
7 Years
Discussion Span
Last Post by vmanes

so far all i get as an output is the name of the first person on the list 2 2. then 2 2 repeating infinitely down the margin


I'm surprised you get even that. Firstly, if you're getting warnings from your compiler, pay attention to them and fix the problems.

#1 - it's int main( ) , not just main( )

#2 - quotatot is used without being initialized - you will get weird results.

#3 - and this is the biggy - your loop for reading data has several problems.
a. - don't use the eof( ) for testing end of input - it's not the best choice, and as you have it structured, it will, in the best case, cause the last line of data (less the name) to be processed twice. You can search on DaniWeb for more explanation on the problem.

b. The mixing of getline and >> for input in one line shouldn't work (doesn't for me in VC++ 2008). You need to break that into two separate input statements. And, in between the getline and the >> usage, you'll need to clear the input, as reaching the string limit length will put the input into a bad state and you won't read the numbers. Oh, and you'll have to get rid of the newline following the numbers, as that prevents the next use of getline from reading the next name.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.