Basically I'm trying to get a number for cin, but when I use the switch statement, it skips over the first (0) and executes all the subsequent switch statements. I know I purposely left off a file or two at the end.
I'm trying to figure out how to make simple console program that simply reads from simple text files that can be expanded. It paints a menu to the console like a batch file
MENU:
Select 1) Enter name/string to first file
Select 2) Enter name/string to 2nd file
Select 3) Enter name/string to 3rd file
Select 4) Enter name/string to 3rd file
Select X) add file option to menu (aka add another file)
Select X) Combine names in all possible combinations from file1/file2/file3/etc (this can be a command line argument), since the input would be the text file names and it would just read down the list and output a CSV/Text file with all possible combinations of words.
Say: Names1.txt, names2txt, etc.
I've found some code on the web that kinda does something heading in the direction but not sure how to modify it, it just randomly selects from a distribution, but the code appears pretty solid.
Basically I just want to input words into seperate files from the command console from the menu and then run an algorithm that can combine any combination of word from any combination of file.
Say there were two files with 4 words in each, or 5 files with 5 words in each and the algo would just tick down the file and
combine each word from each column them all in a list with a space and output it to a text file.
Red, blue
sally, Mod
New file:
red blue
red mod
sally blue
sally mod
blue red
blue sally
mod red
mod sally
Hope this helps. Basically just making a simple "X" name generator that can be expanded (aka you can use it for anything, and you just have files named XX_item to organize the words input from the console. So you you aren't tied to a specific input.
#include <iostream>
#include <fstream>
#include <string>
#include <chrono>
#include <windows.h>
#include <thread>
#include <stdio.h>
#define BUFFER_SIZE 200
using namespace std;
int main() {
ofstream myfile ("stud.txt");
ofstream myfile2("stud2.txt");
ofstream myfile3("stud3.txt");
ofstream myfile4("stud4.txt");
ofstream myfile5("stud5.txt");[tag:tag-name]
ofstream myfile6("stud6.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n";
myfile << "This is another line.\n";
string i;
cout << "*************************************" << "\n";
cout << "****** Enter some data bitch *******" << "\n";
cout << "*************************************" << "\n";
cout << "1. Add file" << "\n";
cout << "2. Add file" << "\n";
cout << "3. Add file" << "\n";
cout << "4. Add file" << "\n";
cout << "5. Add file" << "\n";
cout << "6. Add file" << "\n";
string n = "exit";
char ch;
cin >> ch;
switch (ch) {
case '0':
while (!std::getline(std::cin, i));
{
myfile << i;
cout << "Case 1\n";
}
case '1':
while (!std::getline(std::cin, i));
{
myfile << i;
cout << "Case 1\n";
}
case '2':
while (!std::getline(std::cin, i));
{
myfile2 << i;
cout << "Case 2\n";
}
case '3':
while (!std::getline(std::cin, i));
{
myfile3 << i;
cout << "Case 3\n";
}
case '4':
while (!std::getline(std::cin, i));
{
myfile4 << i;
cout << "Case 4\n";
}
case '5':
while (!std::getline(std::cin, i));
{
myfile5 << i;
cout << "Case 5\n";
}
// myfile << i;
myfile.close();
}
}
Basically looping the input and the menu while reading and writing to multiple files is stumping me because of when I use cin to select it skips over the code of the selected item and executes all subsequent items.
I put enough info in the OP I think.