When I run the following code, and receive the output songs_time.txt file, it doesn't show any of the songs numbers or time remaining in the output table. I have the input songs.txt file path copied into the file_in location but don't know what is wrong. //headers files #include #include #include //using namespace using namespace std; //main() function is defined int main() { cout << "Bartleby---xxxxxxx" << endl << endl; //declaring the variables as per the requirement int song_min, song_sec, total_min, total_sec, total_time = 0, remain_time, remain_min, remain_sec; int serial_num, s_sec; //initialising the holding time of CD to 80 minutes int hold_time = (100 * 60); //reading data from the file fstream file_in("C:\Users\gabri\OneDrive\Desktop\songs.txt", ios::in); //writing data as output on the file fstream file_out("songs_time.txt", ios::out); //displaying the heading of the output table file_out << "\n " << setw(10) << " Song # " << setw(26) << " Song Time " << setw(28) << " Total Time \n"; file_out << setw(40) << " Minutes Seconds " << setw(27) << " Minutes Seconds \n"; file_out << "-------------------------------------------------------------------- "; //using while loop to check the condition repeatedely while (file_in.good()) { //reading the data from the input text file file_in >> serial_num >> s_sec; //calculating the total time total_time = total_time + s_sec; //calculating the total time in minutes total_min = total_time / 60; //calculating the total time in seconds total_sec = total_time % 60; //calculating the total time in minutes song_min = s_sec / 60; //calculating the seconds song_sec = s_sec % 60; //displaying the output on the output file file_out << "\n " << serial_num << setw(22) << song_min << setw(12) << song_sec << setw(16) << total_min << setw(10) << total_sec << " \n"; } //calculating the remaining time remain_time = hold_time - total_time; //calculating the remaining time in minutes remain_min = remain_time / 60; //calculating the remaining time in seconds remain_sec = remain_time % 60; //displaying the message and the remaining time file_out << "\nThere are " << remain_min << " minutes and " << remain_sec << " seconds of space left on the 80-minute CD"; //using the close function file_out.close(); system("pause"); return 0; }
When I run the following code, and receive the output songs_time.txt file, it doesn't show any of the songs numbers or time remaining in the output table. I have the input songs.txt file path copied into the file_in location but don't know what is wrong.
//headers files
#include <iostream>
#include <iomanip>
#include <fstream>
//using namespace
using namespace std;
//main() function is defined
int main()
{
cout << "Bartleby---xxxxxxx" << endl << endl;
//declaring the variables as per the requirement
int song_min, song_sec, total_min, total_sec, total_time = 0, remain_time, remain_min, remain_sec;
int serial_num, s_sec;
//initialising the holding time of CD to 80 minutes
int hold_time = (100 * 60);
//reading data from the file
fstream file_in("C:\Users\gabri\OneDrive\Desktop\songs.txt", ios::in);
//writing data as output on the file
fstream file_out("songs_time.txt", ios::out);
//displaying the heading of the output table
file_out << "\n " << setw(10) << " Song # " << setw(26)
<< " Song Time " << setw(28) << " Total Time \n";
file_out << setw(40)
<< " Minutes Seconds " << setw(27) << " Minutes Seconds \n";
file_out << "-------------------------------------------------------------------- ";
//using while loop to check the condition repeatedely
while (file_in.good())
{
//reading the data from the input text file
file_in >> serial_num >> s_sec;
//calculating the total time
total_time = total_time + s_sec;
//calculating the total time in minutes
total_min = total_time / 60;
//calculating the total time in seconds
total_sec = total_time % 60;
//calculating the total time in minutes
song_min = s_sec / 60;
//calculating the seconds
song_sec = s_sec % 60;
//displaying the output on the output file
file_out << "\n " << serial_num << setw(22) << song_min
<< setw(12) << song_sec << setw(16) << total_min << setw(10) << total_sec << " \n";
}
//calculating the remaining time
remain_time = hold_time - total_time;
//calculating the remaining time in minutes
remain_min = remain_time / 60;
//calculating the remaining time in seconds
remain_sec = remain_time % 60;
//displaying the message and the remaining time
file_out << "\nThere are " << remain_min << " minutes and "
<< remain_sec << " seconds of space left on the 80-minute CD";
//using the close function
file_out.close();
system("pause");
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 6 images