looping

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;
}
1
2
3
4
5
6
mob = 0;
while (mob != 999)
{

  // do things
}
thanxxxxx alot moxchops

i do it but ... its keep looping to the end after i enter 999 ... i want to make it stop loop directly 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;
}
1
2
3
4
5
6
7
while (true)
{

  //get mob number
  if (mob == 999) break;
  // more code
}
Topic archived. No new replies allowed.