i need a help in looping code

Good night every one ... when i run my program its write to the file for only once i mean when i enter for example :
mobile: 77777777
firist name: jey
last name: adam
type: extra
MB: 55
then loping and enter for another customer it write to the file only the data for jey !?



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

void NewCustomerData(){
fstream customer;
customer.open("customers.txt", ios::app);
double MobileNumber,MB;
string FiristName;
string LastName,Type;


do{
cout << "Enter Mobile Number as ( 555 ) to STOP: ";
cin >> MobileNumber;
if(MobileNumber!=-1){
cout<<"Please enter your Firist Name: ";
cin >> FiristName;
cout << "Please enter your Firist Name: ";
cin >> LastName;
cout << "Please enter your Pacage Type";
cin >> Type;
cout << "Please enter how many MG you have been consumed:";
cin >> MB;
customer << MobileNumber << '\t' << FiristName <<'\t' << LastName <<'\t' << Type << "\t"<< MB << endl;
customer.close();}
}
while (MobileNumber!=-1);}


int main(){

NewCustomerData();


return 0;
}
Last edited on
Hello Jey,

FIRST: When you post code here, please use code tags under the format options. Thx

You misspelled First.
also I'm not sure but Pacage, may be spelled Package.
That is not the problem of course. Just wanted to point that out.

Your program tells users to type in the number as (123)456-7890 which is ok, but "()-" are not numbers. Therefor you can not use MobileNumber as a double, int, float or any other numeric value. you can use it as a string, or maybe char. And that seems to be the problem.



thanks Mr.Adams
her is my code


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


void writeData(){
fstream customers;
customers.open("customers.txt", ios::app);
string mob;
string name1 , name2 ,type;
double mb;
do{
cout << "mob (999 to stop): ";
cin >> mob;
if(mob!=999){

cout << "name 1:";
cin >> name1;
cout << "name2 2:";
cin >> name2;
cout<<"tybe :";
cin >> type;
cout<<"mb :";
cin >> mb;
customers << mob << '\t' << name1 <<'\t' << name2 <<'\t' << type<<"\t" <<mb<< endl; } }

while (mob!=999);customers.close();}



int main(){

writeData();

return 0;
}

the problem is when i enter mobile number as 7777777 its write to the file as 7.77778e+007 :(
Topic archived. No new replies allowed.