exit program + save to textFile

Hi , please i want someone to make it like if i press for example -1
exit the programm also i want too how to save to textfile.

thnks


#ifndef Gym_hpp
#define Gym_hpp

#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;


class Gym {

private :
string nameOfExcresice ;
int timeBsets;
int Reps ,Reps1 , Reps2, Reps3, Reps4 ;

public:
Gym();

void details();
void printDetalis();

};

#endif /* Gym_hpp */








#include "Gym.hpp"


Gym::Gym(){

nameOfExcresice= "dumbells";
Reps = 4;
timeBsets=10;


}

void Gym::details(){


cout<<"enter the name of bexecisse : ";
cin>>nameOfExcresice;


cout<<"How many reptition have I done for first rep : ";
cin>>Reps;


cout<<"How many reptition have I done for second rep : ";
cin>>Reps1;


cout<<"How many reptition have I done for third rep : ";
cin>>Reps2;


cout<<"How many reptition have I done for fourth rep : ";
cin>>Reps3;


cout<<"How many reptition have I done for fifth rep : ";
cin>>Reps4;




cout<<"Enter the between each repition : ";
cin>>timeBsets;


}


void Gym::printDetalis(){

cout << "the Name of excesice is : "<<nameOfExcresice <<"\n the number of repetitons : "<<Reps<< ", "<< Reps1<<", "<< Reps2<<", "<< Reps3<<", "<< Reps4<<"\n and time b sets : "<<timeBsets<<" seconds"<<endl;

}









#include <iostream>
#include "Gym.hpp"


int main(){

Gym a ;


for (int i; i>10; i++) {
a.details( );
a.printDetalis();


}


}




closed account (48T7M4Gy)
Maybe you could use code tags and tidy up your code by deleting blank lines and using some formatting.

In the mean time you might also like to consider while loops, while(input != -1) sort of stuff, and to read up on output to files.

Here are a couple of tutorial links.

http://www.cplusplus.com/doc/tutorial/control/

http://www.cplusplus.com/doc/tutorial/files/
To read and write to a Gym object, create << and >> operators:
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
#include <iostream>
#include <string>
class Gym {
private :
    std::string nameOfExcresice ;
    int timeBsets;
    int Reps ,Reps1 , Reps2, Reps3, Reps4 ;

public:
    Gym();

    void details();
    void printDetalis();
    friend std::ostream & operator <<(std::istream &, const Gym&);
    friend std::istream & operator >>(std::istream &, Gym&);
};

std::ostream & operator <<(std::ostream &os, const Gym& g)
{
    // INSERT CODE HERE
    return os;
}

std::istream & operator >>(std::istream &is, Gym& g)
{
    // INSERT CODE HERE
    return is;
}

dhayden Thanks a lot >> but if you can do it with inFile outFile format that would be amazing.



kemort may god bless you
The great thing about creating the >> and << operators is that they can be used with any stream:
1
2
3
4
    Gym g;
    cin >> g;
    ofstream fs("myfile.txt");
    fs << g;


Topic archived. No new replies allowed.