how to write a program to ask for passcode and store information in a file?(written in codeblocks)

#include<iostream>
#include<fstream>
#include<iomanip>
#include<stdlib.h>
using namespace std;

class calculation {
private:
float total,saving;

public:

calculation(){
total = 0;
}

void calmoney(float a,float b) {
total=total+a;
saving=total-b;
cout<<“your total:”<<total<<endl;
cout<<“your saving:”<<saving<<endl;
}

void write_to_file(){
ofstream file;
file.open(“calculation.txt”, ios::app);
file<<“your total: “<<total<<endl;
file<<“your saving: “<<saving<<endl;
file<<“\n”;

file.flush();
file.close();
}

};
int main() {
calculation e;
float c,d;

const int passwd = 12345;
int input_passwd;

std::cout << “Please enter your password: “;
std::cin >> input_passwd;

if (input_passwd == passwd){
std::cout << “\nEnter!\n”;

cout<<“pls enter the total money:”;
cin>>c;
cout<<“pls enter the total money spent:”;
cin>>d;
e.calmoney(c,d);
e.write_to_file();
}
else{
std::cout << “\nSorry! Wrong password!\n”;
}

return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s