Thread: classify numbers update-please help

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    61

    Cool classify numbers update-please help

    Here is thye new program as changes have been made please please anyone who can hlep I'd greatly appreciate it I am a disabled USAF vet and having a hard time so any help would be greatly appreiated

    Code:
    Program: Classify Numbers
    This program counts the number of zeros, odd, and even numbers *?*/
    
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    
    using namespace std;
    
    
        //Function prototypes
    void initialize(int& zeroCount, int& oddCount, int& evenCount);
    void getNumber(int& num);
    void classifyNumber(int num, int& zeroCount, int& oddCount, 
                        int& evenCount);
    void printResults(int zeroCount, int oddCount, int evenCount);
    bool getNumber(ifstream& numberFile, int& zeros, int& odds, int& evens);
    void writeNumber(ofstream& resultsFile, int zeros, int odds, int evens, 
         int sum, int avg);
    int calcSum( int zeros, int evens, int odds);
    
    int main ()
    {
        
        ifstream numberFile;
        ofstream resultsFile;
        int N;  
        int sum;
        int avg; 
        
    
        
        
            //Variable declaration
        int counter; //loop control variable 
        int number;  //variable to store the new number 
        int zeros;   //variable to store the number of zeros 
        int odds;    //variable to store the number of odd integers s
        int evens;   //variable to store the number of even integers 
        //int sum;     // sum of the numbers
        //int avg;     //average of the number
    
        initialize(zeros, odds, evens);                 //Step 1
    
        //cout << "Please enter " << N << " integers."
         //    << endl;                                   //Step 2
        //cout << "The numbers you entered are: "
         //    << endl;
    
    //numberfile.open ("f:number.dat");
    
              //  if(inFile)
                //cout<< "Open \ 'f:numberfile.dat\' " << endl;
                //else
                     
                //cout << "File not opened \ 'f:number.txt\' << endl;
                
    numberFile.open ("f:number.dat");
    if(numberFile)
                  {                 //failure of opening number file
                  cout << "Error in opening number file .\n" << endl;
                  system ("pause");
                  return 0;
                  }
    resultsFile.open("f:results.dat");
    if(!resultsFile)
                    {                 //failure of opeinging results file
                    cout << "Error in opening results file .\n" << endl;
                    
                    system("pause");
                    return 0;
                    }
                    
    while ( getNumber (numberFile, zeros, odds, evens))
          {
         
        for (counter = 1; counter <= N; counter++)      //Step 3
        {
            getNumber(number);                          //Step 3a
            cout << number << " ";                      //Step 3b
            classifyNumber(number, zeros, odds, evens); //Step 3c
        }// end for loop 
    
        // calcSum (zeroCount,  evenCount,  oddCount);
          writeNumber(resultsFile, zeros, odds, evens, sum, avg);
          }
    
        
        cout << endl;
    
        printResults(zeros, odds, evens);               //Step 4
    
        return 0;
    }
    
    void initialize(int& zeroCount, int& oddCount, int& evenCount)
    {
        zeroCount = 0;
        oddCount = 0;
        evenCount = 0;
    }
    
    void getNumber(int& num)
    {
        cin >> num;
    }
    
    void classifyNumber(int num, int& zeroCount, int& oddCount,
                        int& evenCount)
    {
        switch (num % 2)
        {
        case 0: 
            evenCount++;  
            if (num == 0)
                zeroCount++;  
            break;
       case 1: 
       case -1: 
           oddCount++;
          
       } //end switch
    }
    
    int calcSum( int zeroCount, int oddCount, int evenCount)
    {
        calcuSum =(zeroCount + oddCount + evenCount);
    }
        
    
    void printResults(int zeroCount, int oddCount, int evenCount)
    { 
       cout << "There are " << evenCount << " evens, "
          << "which includes " << zeroCount << " zeros"
        << endl;
    
     cout << "The number of odd numbers is: " << oddCount
        << endl;
        
    // calcuSum
    }
    Last edited by BJtoVisualcC++; 06-17-2007 at 06:48 PM. Reason: code tags

  2. #2

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    code-dynasty said refused to show the page
    I put in the code tags---also I foudn my own error in the bottom calcuSum it is misspelled but it still has an error in that function

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I put in the code tags
    no you didn't... reread Desolation's links... but this time, read them slower.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    903
    Quote Originally Posted by BJtoVisualcC++ View Post
    code-dynasty said refused to show the page
    I put in the code tags---also I foudn my own error in the bottom calcuSum it is misspelled but it still has an error in that function
    Code-dynasty is a site that doesn't exist and it is not part of my post, it's in my sig. I'm just too lazy to remove it. Besides, do as robwhit said and re-re-read the threads I've linked for you.

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    You can send the links but when I put the code in and am starting a new thread I use the part that says code tags it has a # sign and I clicked on it at the beginning and end--so I am supposed to type tag? When y6u start a new thread it has a "#" that says code tag

  7. #7
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    I'm not trying to be smart or anything just wandering why the part has code tag as an option and it doesn't work?

  8. #8
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    Hey, point scored for me figured out the code tagging business-I hope thanks everyone for being nice and helping me with the problems

  9. #9
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    I want to say a special thanks to mike_g for all of your help and thanks for the link to figure out the code tag Desolation--at least I hope I did

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    903
    I think you need help with the edit button as well.

  11. #11
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    what edit button-I did use it to put the code tags-are you tryin to bust my chops? your remarks are cold and not helpful when you say what you just said-look how long I've been at ths-a week

  12. #12
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    like I said in the other posting this is an internet course-no one to help--

  13. #13
    Registered User
    Join Date
    May 2006
    Posts
    903
    I'm just trying to help you out. Posting four times in a row is not something to boost your reputation. Simply use the edit button. It's simple and quick.

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    well, congrats where congrats are due. congrats
    here it tests for success

    numberFile.open ("f:number.dat");
    if(numberFile)
    { //failure of opening number file
    here it tests for failure.
    resultsFile.open("f:results.dat");
    if(!resultsFile)
    { //failure of opeinging results file
    what edit button
    lower right hand corner of your posts.
    Last edited by robwhit; 06-17-2007 at 10:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Matching numbers
    By kirksson in forum C Programming
    Replies: 7
    Last Post: 07-23-2008, 01:51 PM
  2. Question about random numbers
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 07-02-2008, 06:28 AM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 10:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM