how we can enter a number to go out of the loop??

hii guys i really neeeeeeeeeed a heeeeeeeeelp in that:
Open the customers file in append mode.
b. Allow the administrator to enter the customer mobile number,name,data pack plan and the actual megabytes MBs of data consumed by the customer.
c. Write the entered data to the customers file.
d. Keep looping until the administrator enters (999) as the mobile number, to stop entering data and go back to the main menu.

its my code but i dont know how to make it looping ?

#include <iostream>
#include <fstream>
#include<string>
using namespace std;

int main()
{
ofstream customerfile("customes.txt", ios::in | ios::out | ios::app);
int mob,mb;
string name1,name2,type;

cout<<" please enter your mobile number: "<<endl;
cin>>mob;

cout<<" please enter your firist name: "<<endl;
cin>>name1;

cout<<" please enter your last name : "<<endl;
cin>>name2;

cout<<" please enter your pack type : "<<endl;
cin>>type;

cout<<" please enter how many MB's you have been consumed : "<<endl;
cin>>mb;

customerfile <<mob<<"\t"<<name1<<"\t"<<name2<<"\t"<< type<<"\t"<< mb<<"\t"<< endl;

customerfile.close();

return 0;
}
A loop has a condition: while the condition is true, the loop keeps executing.

In your case, the condition is that the administrator doesn't enter 999 as the mobile number.

1
2
3
4
5
6
7
8
9
10
11
// ...

while (mob != 999)
{
    cout << "Please enter your mobile number: ";
    cin >> mob;

    // ...
}

// ... 
the alot catfish3

i do it but ... its keb looping to the end after i enter 999 ... i want to make it stop loop direct after i enter 999 as a mob...

#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main ()
{ int mob,mb;
string name1,name2,type;
ofstream customerfile("customes.txt", ios::in | ios::out | ios::app);

do {

cout<<" please enter your mobile number: "<<endl;
cin>>mob;

cout<<" please enter your firist name: "<<endl;
cin>>name1;

cout<<" please enter your last name : "<<endl;
cin>>name2;

cout<<" please enter your pack type : "<<endl;
cin>>type;

cout<<" please enter how many MB's you have been consumed : "<<endl;
cin>>mb;

customerfile <<mob<<"\t"<<name1<<"\t"<<name2<<"\t"<< type<<"\t"<< mb<<"\t"<< endl;

customerfile.close();

} while (mob!=999);
return 0;
}
@heba

u can do like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(){
      bool match = 1;
      //.....Your code...

      do{
           //...Implementation
           if( mob == 999 )
                   match = false;   
           else
                    match = true;

           //...Other code here

      while( found );
Last edited on
Topic archived. No new replies allowed.