Why Won't My Loop Put In The CSV My Pattern?
Mar 26, 2017 at 1:14am UTC
If you look at my loop here - I can't get the CSV it makes to contain everything I see in my application - any ideas? You're all so awesome for the expertise !
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#include <iostream>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
int hh;
int mm;
int ss;
int pick;
int ss_choice;
int mm_choice;
int hh_choice;
int ss_hh;
int ss_mm;
int ss_ss;
int mm_hh;
int mm_mm;
int mm_ss;
int hh_hh;
int hh_mm;
int hh_ss;
cout << "Give Me A Start Time Please:\n" ;
char sep;
cin >> hh >> sep >> mm >> sep >> ss;
cout << "Choose An Increment Type Please:\n" ;
cout << "1. Seconds:\n" ;
cout << "2. Minutes:\n" ;
cout << "3. Hours:\n" ;
cin >> pick;
if (pick==1) {
char sep;
cout << "How Many Seconds?:\n" ;
cin >> ss_choice;
cout << "What's Your End Time?:\n" ;
cin >> ss_hh >> sep >> ss_mm >> sep >> ss_ss;
do {
ofstream myfile;
myfile.open ("output.csv" );
myfile << setfill('0' ) << setw(2) << hh << ":" << setfill('0' ) << setw(2) << mm << ":" << setfill('0' ) << setw(2) << (ss += ss_choice) << endl;
cout << setfill('0' ) << setw(2) << hh << ":" << setfill('0' ) << setw(2) << mm << ":" << setfill('0' ) << setw(2) << (ss += ss_choice) << endl;
if (ss >= 59) mm++, ss=00;
if (mm >= 59) hh++, mm=00,ss=00;
}
while (hh <= ss_hh);
return 0;
}
else if
(pick==2)
{
char sep;
cout << "How Many Minutes?:\n" ;
cin >> mm_choice;
cout << "What's Your End Time?:\n" ;
cin >> mm_hh >> sep >> mm_mm >> sep >> mm_ss; // loop will be repeated once fixed.
do {
cout << setfill('0' ) << setw(2) << hh << ":" << setfill('0' ) << setw(2) << (mm += mm_choice) << ":" << setfill('0' ) << setw(2) << ss << "\n" ;
if (ss >= 60) mm++, ss=00;
if (mm >= 60) hh++, mm=00,ss=00;
}
while (hh <= mm_hh);
return 0;
}
else if
(pick==3)
{
char sep;
cout << "How Many Hours?:\n" ;
cin >> mm_choice;
cout << "What's Your End Time?:\n" ;
cin >> hh_hh >> sep >> hh_mm >> sep >> hh_ss;
do {
cout << setfill('0' ) << setw(2) << (hh += hh_choice) << ":" << setfill('0' ) << setw(2) << mm << ":" << setfill('0' ) << setw(2) << ss << "\n" ;
if (ss >= 60) mm++, ss=00;
if (mm >= 60) hh++, mm=00,ss=00;
}
while (hh <= hh_hh);
return 0;
}
return 0;
}
Mar 26, 2017 at 3:58am UTC
"A CSV is a comma separated values file which allows data to be saved in a table structured format. CSVs look like a garden-variety spreadsheet but with a .csv extension (Traditionally they take the form of a text file containing information separated by commas, hence the name)." Source:
https://support.bigcommerce.com/articles/Public/What-is-a-CSV-file-and-how-do-I-save-my-spreadsheet-as-one
By looking at your code (line 46-47), I do not see a comma separating the values.
To give you an idea, the following code creates a csv file of a multiplication table (100 x 100)
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
#include <iostream>
#include <fstream>
int main()
{
const int max_Rows{ 101 };
const int max_Cols{ 101 };
std::ofstream outPutFile;
outPutFile.open("Multiplication Table.csv" );
int multiplicationTable[max_Rows][max_Cols];
for (int countRows = 0; countRows < max_Rows; countRows++)
{
for (int countCols = 0; countCols < max_Cols; countCols++)
{
multiplicationTable[countRows][countCols] = countRows * countCols;
outPutFile << multiplicationTable[countRows][countCols] << "," ;
}
outPutFile << std::endl;
}
outPutFile.close();
return 0;
}
Mar 26, 2017 at 1:27pm UTC
Move line 43 below line 45. Right now the loop re-opens the output file for each value and writes the output to be beginning of the file, erasing previous value.
Mar 27, 2017 at 1:53am UTC
dhayden - Worked like a champ. Thank you so much!
Mar 27, 2017 at 1:54am UTC
chico - thank you for the ideas!
Topic archived. No new replies allowed.