Count++ not adding to initial count

Hello, I have spent hours on this project and am hoping for some help. I have been trying to get my counts to work but every time I run the program it outputs 0 for the count. for some reason my count is not being affected by the if statements. The if statements sort the files just don't have any effect on the counts. thanks for the help!

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>

using namespace std;

int main()
{
string media = "unsorted_media.txt";
string movies = "movies.txt";
string music = "music.txt";
string images = "images.txt";
string error = "error.txt";
string ext;

int countUM = 0, countM = 0, countU = 0, countI = 0, countE = 0;

string current;

ifstream inFile;

ofstream outMovies;
ofstream outMusic;
ofstream outImages;
ofstream outError;

inFile.open(media);
outMovies.open(movies);
outMusic.open(music);
outImages.open(images);
outError.open(error);


inFile >> media;

while (inFile)
{
inFile >> media;
countUM++;
}




while (inFile)
{

ext = media.substr(media.length() - 4);

if (ext == ".avi" || ext == ".mkv" || ext == ".mov" || ext ==
".mp4" || ext == ".wmv")
{
outMovies << media << endl;
countM++;


}


else if (ext == "flac" || ext == ".m4a" || ext == ".mp3" || ext
== ".wav" || ext == ".wma")
{
outMusic << media << endl;
countU++;

}

else if (ext == ".bmp" || ext == ".gif" || ext == ".jpg" || ext
== ".png" || ext == "tiff")
{
outImages << media << endl;
countI++;
}

else
{
outError << media << endl;
countE++;
}

inFile >> media;

}


cout << "\n\t\tYou have " << countUM << " files to sort.\n\n";

system("pause");

system("cls");




cout << countM;

system("pause");
return 0;

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>

int main()
{
    const std::string unsorted_media_file_name = "unsorted_media.txt" ;
    const std::string movies_file_name = "movies.txt" ;
    const std::string music_file_name = "music.txt" ;
    const std::string images_file_name = "images.txt" ;
    const std::string error_file_name = "errror.txt" ;

    if( std::ifstream input_file{unsorted_media_file_name} ) // if the input file was opened
    {
         std::ofstream movies_file(movies_file_name) ;
         std::ofstream music_file(music_file_name) ;
         std::ofstream images_file(images_file_name) ;
         std::ofstream error_file(error_file_name) ;

         int count_movies = 0 ;
         int count_music = 0 ;
         int count_images = 0 ;
         int count_errors = 0 ;

         const std::string movie_ext = ".avi .mkv .mov .mp4 .wmv" ;
         const std::string music_ext = ".flac .m4a .mp4 .wav .wma" ;
         const std::string image_ext = ".bmp .gif .jpg png tiff" ;

         std::string item_name ;
         while( std::getline( input_file, item_name ) ) // for each line read from the file
         {
             std::string ext = "invalid extension" ;
             if( item_name.size() > 4 )
             {
                 ext = item_name.substr( item_name.size() - 4 );
                 for( char& c : ext ) c = std::tolower(c) ; // make it all lower case
             }

             if( movie_ext.find(ext) != std::string::npos )
             {
                 movies_file << item_name << '\n' ;
                 ++count_movies ;
             }
             else if( music_ext.find(ext) != std::string::npos )
             {
                 music_file << item_name << '\n' ;
                 ++count_music ;
             }
             else if( image_ext.find(ext) != std::string::npos )
             {
                 images_file << item_name << '\n' ;
                 ++count_images ;
             }
             else
             {
                 error_file << item_name << '\n' ;
                 ++count_errors ;
             }
         }

         std::cout << "movies: " << count_movies << '\n'
                   << " music: " << count_music << '\n'
                   << "images: " << count_images << '\n'
                   << " error: " << count_errors << '\n'
                   << "-----------------------\n"
                   << " total: " << count_movies + count_music + count_images + count_errors << '\n' ;
    }

    else std::cerr << "could not open input file\n" ;
}
Topic archived. No new replies allowed.