i'm just a beginner here..so forgive me if i make some mistakes ><!here's the problem,sometimes during compiling,i input a correct number but the sub total output gives a absurdly huge number and sometimes it just works normally,i don't know what is wrong here.i hope u guys can help n enlighten me!thanks!
int main()
{
ofstream file;
file.open("grcr2.txt", ios::in|ios::out|ios::trunc);
if (!file.is_open())
{
cout<<"error while opening the file";
}
else
{
int z;
char ans, y,n;
const int num1=10000;
cout<<"Enter number of items: ";
cin>>z;
if(z<=0)
{
cout<<"invalid number of items.";
return 0;
}
string name[num1]={""};
string date[num1]={""};
double number[num1]={NULL},cost[num1]={NULL}, TC[num1]={NULL},cash,change1,TTC;
cin.ignore(1024,'\n');
for(int i=0;i<z;i++)
{
cout << "\nEnter name of ITEM "<< i+1 <<"(t to terminate): ";
getline(cin,name[i]);
if(name[i]=="t")
{
name[i]="";
break;
}
cout << "Enter date of purchase: ";
cin >> date[i];
cout << "Enter amount of item: " ;
cin >> number[i];
cout << "Enter the cost of item: ";
cin >> cost[i];
cin.ignore(1024,'\n');
TC[i]=number[i] * cost[i];
TTC += TC[i]; //this line is the calculation for sub total i dont know if this code will cause some glitches or not.
else
{
cout<<" NOT ENOUGH CASH!"<<endl;
file<<" NOT ENOUGH CASH!"<<endl;
}
file.close();
cout<<"Do you want to open textfile?(input y or n): ";
cin>>ans;
if(ans=='y')
{
ShellExecute(NULL,"open","notepad.exe","grcr2.txt",NULL,SW_SHOWNORMAL);
system("PAUSE");
}
return 0;
}