Home Forums C Programming hi…. Re: Re: hi….

#3557
GWILouisaxwzkla
Participant

heres a start ( I’m not certain why you are dividing every purchase in the program by 1000 ) . By the way don’t use “gotos” in high level programming languages , this is considered bad programming practice ( google Dijkstra ). Anyway , this is how I might code what you have ( the total comes out 0 since everything is divided by 1000 ). Anyway……..



#include
#include
#include

float b=1000;
void main()
{
//clrscr();

int total = 0;
double amount;
double temp;
char choice;
cout << "nwelcome 2 my grocery store!!!!";
cout << "nwould u like 2 see the items available for purchase(y/n)? ";
cin >> choice;
cin.get();
if ( choice == 'Y' || choice == 'y' )
{

do
{

cout << "the items available are:";
cout << "nno."<<'t'<<"item "<<'t'<<"quantity(b)(in grams)"<<'t'<<"m.r.p(c)";
cout << "n---"<<'t'<<"---- "<<'t'<<"
"<<'t'<<"
";
cout << "n1. "<<'t'<<"urad dal "<<'t'<<"1000g "<<'t'<<"Rs.50.25";
cout << "n2. "<<'t'<<"tur dal "<<'t'<<"1000g "<<'t'<<"Rs.60.75";
cout << "n3. "<<'t'<<"tea powder "<<'t'<<"1000g "<<'t'<<"Rs.200.0";
cout << "n enter choice => ";
cin >> choice;
cin.get();


if( choice == '1' )
{
cout << "nenter the amount of the item u want to purchase ";
cin >> amount;
temp = ( amount * 50.25 ) / 1000.00;
total = temp + total;
cout << "n the amount to be paid is:" << temp << "n";
}
else if( choice == '2' )
{
cout << "nenter the amount of item ";
cin >> amount;
temp = ( amount * 60.75 ) / 1000.00;
total = temp + total;
cout << "nthe amount 2 b paid is:" << total << "n";
}
else if( choice == '3' )
{
cout << "nenter the amount of item ";
cin >> amount;
temp = ( amount * 200.00 ) / 1000.00;
total = temp + total;
cout << "nthe amount 2 be paid is:" << total << "n";
}
cout << "ndo u want to buy another item? ";
cin >> choice;
cin.get();
} while ( choice == 'y' || choice == 'Y' );

cout<<"nplease wait.... ur bill is being calculated...." << endl;
cout << "the total is " << total << endl;


cout << "nplease pay the requested amount" << endl;
cout << "nthank you.please visit again" << endl;

cout<<"nthanks for visiting my store !!!" << endl;

}
cout << "nthank you.kindly try purchasing the next time u visit the store!!!!!" << endl;

getch();
}