Jul 21, 2018 at 3:07am UTC
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;
}