I have just started studying C++ and am trying to write an interactive C++ program. The program should be a form of supermarket receipt. The format/sample is given below

CASH 20000

ITEM(S) PRICE

Soap 2000
beef 3000
cake 1500
book 2000
Bags 4000

CHANGE 7500

I have tried my best but i couldn't produce the right code. please any form of assistance highly appreciated

>I have tried my best but i couldn't produce the right code.
Post your best attempt and we'll help you correct it.

>I have tried my best but i couldn't produce the right code.
Post your best attempt and we'll help you correct it.

Hi thanks for willing to assist. Here is the code:

#include <iostream.h>
int Balance;
 char name [4];
int price, cash, total=0;
int main()
{

cout<<"Enter the cash ";
cin>>cash;
cout<<"cash\t\t\t"<<cash<<'\n';
cout<<"ITEM(S)\t\t\t"<<"PRICE\n";
cout<<"............................."<<'\n';
do
{
cout<<"Enter product Name";
cin>>name;

cout<<"Enter price of the item";
cin>>price;
cout<<name <<"\t\t\t"<<price<<'\n';
cout<<".............................."<<'\n';
total=total+price;
}
while (name != "i");
Balance=cash-total;
cout<<"TOTAL\t\t\t"<<total;
cout<<"BALANCE\t\t\t"<<Balance;

return 0;
}

samjars,
two suggestions:
1. when comparing two strings you may want to use the strcmp function on string.h
Have a look at http://www.daniweb.com/forums/thread5663.html

2. you'd like to think about controlling the flow with another type of loop... otherwise you need to enter price=0 for item i.

> I supposed I could mention this, but chances are you'll ignore it.
> http://www.daniweb.com/forums/announcement8-3.html

Oh well, that's it then
> Last edited by Narue : 8 Hours Ago at 21:41. Reason: added code tags

Move along, nothing to see here.

Just another starving man, who on stumbling upon a banquet was unable to recognise that what was being offered was food.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.