So I've worked on my first big program in a DOS Screen, it's where you input a command and it'll return the function defined with it (duh) It's not working for some reason though.
Code for main.cpp
ofstream new_account(naming_interger".dat"); is where it mainly fails to compile, I am using Dev-C++ 4.9.9.2.Code:#include <fstream> #include <stdlib.h> #include <iostream> using namespace std; //Storing code: "int args, char *argv[]" int main() { int input; float moneyvar; char naming_interger; float new_money; float math; int input2; cout<< "Welcome to the Payback Bank!\nType new to create an account.\nType get to see a file.\nType change to add or subtract money owed.\nType clear to clear all owed money from an account."; cin>> input; cin.ignore(); switch ( input ) { case 'NEW': cout<< "Who owes you money? Please type the name:\n"; cin>> naming_interger; ofstream new_account(naming_interger".dat"); cout<< "The person who owes you money is "<< naming_interger<< "\nHow much are you owed?"; cin>> new_money; cin.ignore(); cout<< "Writing money to file..."; new_account << new_money; cout<< "Done! The process was successful!\n"; cout<< "The person "<< naming_interger<< " owes you "<< new_money<< "\n"; new_account.close(); system("PAUSE"); return 0; break; case 'GET': cout<< "Who's account would you like to view?\n"; cin>> naming_interger; cin.ignore(); ifstream read_account(naming_interger".dat"); if (read_account.fail()) { cout<< "There was an error, perhaps the file doesn't exist?\n"; system("PAUSE"); } cout<< naming_interger<< " owes you "<< read_account<< "\n"; read_account.close; system("PAUSE"); break; case 'CHANGE': cout<< "Who's account are you changing?"; cin>> naming_interger; cin.ignore(); ifstream change_account(naming_interger".dat"); change_account>> moneyvar; if (read_account.fail()) { cout<< "There was an error, perhaps the file doesn't exist?\n"<<; system("PAUSE"); } cout<< "You loaded "<< naming_interger<< "'s account.\nHe/She owes you"<< moneyvar<< "\nHow much do you want to add? (HINT: Place a - to subtract)\n"; cin>> math; cin.ignore(); cout<< "Adding money to account, please wait...\n"; moneyvar = moneyvar + math; ofstream update_account(naming_interger".dat"); moneyvar>> update_account; update_account.close; cout<< "The account update was succesful!\n"; system("PAUSE"); break; case 'CLEAR': cout<< "Who paid back your money?\n"; cin>> naming_interger; cin.ignore(); ifstream clear_account(naming_interger".dat"); clear_account>> moneyvar; { cout<< "There was an error, perhaps the file doesn't exist?\n"<<; system("PAUSE"); } cout<< "You loaded "<< naming_interger<< "'s account.\n"; cout<< "Clear this account's data? (y/n)This does NOT erase the account.\n"; cin>>input2; if (input == y) { cout<< "Erasing owed money data."; moneyvar = 0; ofstream clearing_account(naming_interger".dat"); clearing_account.close cout<< "The account's owed money was cleared successfully!\n"; system("PAUSE"); } else { return 0; } break; default: { cout<< "Failure to read command.\n"; system("PAUSE"); break; } } } }
My guess is that you can't store a variable into a file's name, but I want to, can I get some help here?
What this program's plot is is it loads and saved accounts on how much money somone owes you.



LinkBack URL
About LinkBacks


