HELP!!

i have this code that gets a number of car objects and i am stuck in some sort of loop at the line which i put on bold. when i finish initializing my first object, it's suppose to go back to the menu and prompt the user but instead it goes into an uncontrolled loop for about 20 times (oddly) and then stops at the menu











#include<iostream>
#include<conio.h>
#include<iomanip>
#include<string>
#include<time.h>
#include<cmath>
#include<fstream>
#include<windows.h>

using namespace std;
class order
{
string model;
string first_name;
string last_name;
string tel;
string service_description;
float total_cost;
int last_service;
int services_yearly;
int next_service;
public:
friend istream& operator >>(istream &in, order &s);
void next_appointment();
static void save(order c[], int num);
static void time_function();
static char menu();
order();
};

void order::save(order c[], int num)
{
ofstream file1("order.dat");
file1.write((char*)c,sizeof(order)*num);
file1.close();
}

char order::menu()
{
char choice;
do
{
time_function();
cout<<"\tMENU"<<endl;
cout<<"Please choose an option"<<endl;
cout<<"1. Add records"<<endl;
cout<<"2. Look for a record"<<endl;
cout<<"3. Delete a record"<<endl;
cout<<"4. Look for appointments by date"<<endl;
cout<<"5. Exit the program"<<endl<<endl;
cin>>choice;
if((int)choice<49 || (int)choice>54)
{
system("cls");
cout<<"\awrong input entry you!"<<endl;
Sleep(1800);
}
}
while((int)choice<49 || (int)choice>54);
return choice;
}
istream& operator >>(istream &in, order &s)
{
cout<<"what is your first name? > ";
fflush(stdin);
getline(in,s.first_name);
cout<<"what is your last name? > ";
fflush(stdin);
getline(in,s.last_name);
cout<<"what is your telephone number? > ";
fflush(stdin);
getline(in,s.tel);
cout<<"what is the car model? > ";
fflush(stdin);
getline(in,s.tel);
cout<<"how many services a year? > ";
fflush(stdin);
in>>s.services_yearly;
cout<<"how many months ago was the last service done? > ";
fflush(stdin);
in>>s.last_service;
cout<<"describe your service > ";
in>>s.service_description;
return in;
}
void order::next_appointment()
{
next_service=(12/services_yearly)-last_service;
if(next_service>1)
cout<<"your next service is due in "<<next_service<<" months"<<endl;
else if(next_service==1)
cout<<"your next service is due in "<<next_service<<" month"<<endl;
else
cout<<"your next service is due now"<<endl;
system("pause");
}
void order::time_function()
{
system("cls");
system("color 1e");
time_t current_time;
current_time=time(NULL);
cout<<"\t\t\tEST - "<<ctime(&current_time)<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
}
order::order()
{
first_name="\0";
last_name="\0";
tel="\0";
service_description="\0";
model="\0";
}

void main()
{
order *ptr;
int x;
char choice;
do
{
order::time_function();
cout<<"1. New file " <<endl;
cout<<"2. Existing file ";
cin>>choice;
if((int)choice==49)
{
order::time_function();
cout<<"\tAdd a new record menu"<<endl<<endl;
cout<<"How many new records to create? > ";
cin>>x;
ptr = new order[x];
for(int i=0;i<x;i++)
{
cin>>ptr[i];
ptr[i].next_appointment();
order::time_function();
}
order::save(ptr,x);
cout<<"Thank you for choosing MR LUBE!";
Sleep(1800);
}
else if((int)choice>50)
{
cout<<"\awrong input entry you!"<<endl;
Sleep(1800);
}

}
while((int)choice>50 || (int)choice<49);
for(;;)
{
choice=order::menu(); //ERROR RIGHT HERE
order::time_function();
switch((int)choice)
{
case 49:
{
break;
}
case 50:
{
break;
}
case 51:
{
break;
}
case 52:
{
break;
}
case 53:
{
exit(0);
break;
}
}
}
delete []ptr;
getch();
}



can someone help me plzzzz
Last edited on
Please edit and use code tags by clicking <> under the format option.
closed account (Dy7SLyTq)
is it valid to access data member functions without an object with the scope object?
Yes if its static
Topic archived. No new replies allowed.