So I was only going to come on here for help with some thing more complicated but then I made this error where I can't end the function as I planned.
I had a perfectly working program doing as I intended. I realised in my user choice section of my program I hadn't entered a quit option or a correct method of repeating the input if the user enters the data incorrectly. I figured it would be fine just add some if statements. However when I run through my program instead of ending it repeats again when the if statement condition isn't even met.
The issue I'm having is with my usercontrol function where the user decides what action they want to do. It is then meant to end the usercontrol function and move through the rest of intmain() and finish. I previously didn't have usercontrol as a int return but I had to, to use return 0 for the "quit option" because I didn't see an alternative. The only issue is with exiting the usercontrol function since I've added the quit and if incorrect input actions. I'm having issues with my if statement.
ADDITIONAL QUESTIONS (NOT MAIN QUESTION)
Q1) The program is a note program with addition utility. So as an added thing I want to add audio recordings into my program. I know I have to find the correct header/ library which I can use to record audio but that has been tricky because the ones I've seen I couldn't get working correctly (maybe I was doing wrong. So if some one can tell me what headers to use if it's available in the standard library or if I need to add an additional library what is it and how do I add it?
Q2) At the bottom of my writetofile function is my method of creating a time stamp for the file is there any way of not making my console output the time stamp when it creates my txt file to hold the time stamp?
Q3) If I wanted my user to be able to edit a txt file they have previously created what can I add to my writetofile function to allow them to edit and add to the previously written txt file.
Q4) My read command requires the user inputs the name of an existing file is there a method of showing a list of those files for the user to see so they can input the title of the note?
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include <iostream>
#include <fstream>
#include <math.h>
#include <cstdlib>
#include <string>
#include <ctime>
#include <cstdio>
using namespace std;
int usercontrol();
void writetofile();
void read();
void spellcheck();
void audiorecording(); // http://pastebin.com/7Ymxcs57 // http://pastebin.com/MHmgTJgk //
string inputtext;
string filename;
string outputtime;
int main()
{
usercontrol();
cin.ignore();
cin.get();
return 0;
}
int usercontrol()
{
string choice;
cout << "enter your choice of action "<< endl;
cout << "please enter either "<< "write, " << "read, " << "or," << " quit" << endl;
cin >> choice;
if (choice == "write")
{
writetofile();
}
if (choice == "read" )
{
read();
}
if (choice == "quit")
{
return 0;
}
else if (choice != "write","read", "quit")
{
cout << "incorrect input. Please try again." << endl;
usercontrol();
}
return 0;
}
void writetofile()
{
cout << "name your note" << endl;
cin >> filename;
ofstream output(filename+".txt");
cout << "You are free to enter your text. To finish your note type 'QUITNOTE' " << endl;
string inputtext;
while (getline(cin, inputtext) && (inputtext != "QUITNOTE"))
output << inputtext << endl;
output.close();
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%c",timeinfo);
puts (buffer);
string stringtime;
stringtime = buffer;
cout << stringtime;
ofstream outputtime;
outputtime.open (filename+"_info.txt");
outputtime << stringtime;
outputtime.close();
}
void read()
{
string filedata;
string timecreated;
cout << "Name the file you want" << endl;
cin >> filename;
ifstream in(filename+".txt");
while (getline(in, filedata ))
cout << filedata << endl;
in.close();
ifstream read(filename+"_info.txt");
while (getline(read, timecreated))
cout << timecreated;
}
|
Thanks for your time.