Hi..
This is my program for my assignment..
So far,I've succeeded in coding the program but not for the last part..
I still need to find the total sale for this program...
and the result at the end suppose to be more or less like this :

Total sale : $25.00
Payment : $50.00
Balance : $25.00

I've tried so hard,but still i cant find the right way to do it..
So i hope you all could me....
Thank You..:)

#include <iostream>
#include <iomanip>
using namespace std;

int main () {

class record{
public :
   string id;
   string name;
   double price;
   double quantity;
   double sale;
   };

  record product[100];


      int i=0;
      char answer;

      cout<<"--------------------------------------------------------------------------------";
      cout<<"\t\t\t\tCASH RECEIPT PROGRAM"<<endl;
      cout<<"--------------------------------------------------------------------------------";
      cout<<endl;

      do{

      cout << "Enter the Product ID : ";
      cin >> product[i].id;


      cout << "Enter the Product Name : ";
      cin >> product[i].name;


      cout << "Enter the Price For Single Item : ";
      cin >> product[i].price;

      cout << "Enter The Quantity : ";
      cin >> product[i].quantity;

      cout<<endl;

      cout << "Would You like to enter another product? (Y/N) ";
      cin >> answer;


      i++;

      cout<<endl;

      }while(answer == 'y' || answer == 'Y' && answer !='N'&&'n');



if (answer == 'N' || 'n'){

int index;

cout<<"--------------------------------------------------------------------------------";
cout<<"ID |"<<setw(13)<<"ITEM |"<<setw(12)<<"PRICE |"<<setw(10)<<"QTY |"<<setw(10)<<"SALE"<<endl;
cout<<"--------------------------------------------------------------------------------";


 for(index=0; index<i; index++){

product[index].sale=(product[index].price)*(product[index].quantity);

// Display all the info about that product
cout <<product[index].id<<setw(10)<<product[index].name<<setw(10)<<"$"<<product[index].price<<setw(10)
<<product[index].quantity<<setw(10)<<product[index].sale;

cout<<endl;


}

}

cin.get();

}

Edited 7 Years Ago by samsons17: n/a

you could probably do something like this:

int total = 0;

for(int counter=0; counter < i; counter++)
{
     total += product[counter].price;
}

cout << "Total goods sold is:  " << total;

Good looking well coded program btw. The only critique I have is that I would probably use a struct over a class, mainly because struct access is automatically made 'public' whereas with classes you have to use an extra line of code to change access to public.

Also, one mistake here:

}while(answer == 'y' || answer == 'Y' && answer !='N'&&'n');

//should be
}while((answer == 'y' || answer == 'Y') && (answer != 'N' || answer !='n'));

Although if you test for Y, you know your only other option would be N, so why even test for N...

Also, line #57 does not need to exist, because if you fall through the do/while loop, you can assume that the user no longer wants to input data and you can just continue with the rest of the program.

Edited 7 Years Ago by Clinton Portis: n/a

Explain your confusion a little more. Wouldn't you just add up all of the product[index].sale values then prompt the user for a payment amount?

Edited 7 Years Ago by jonsca: n/a

Thank you..now my problem is solved.....

you could probably do something like this:

int total = 0;

for(int counter=0; counter < i; counter++)
{
     total += product[counter].price;
}

cout << "total goods sold is:  " << total;

good looking well coded program btw. The only critique i have is that i would probably use a struct over a class, mainly because struct access is automatically made 'public' whereas with classes you have to use an extra line of code to change access to public.

Also, one mistake here:

}while(answer == 'y' || answer == 'y' && answer !='n'&&'n');

//should be
}while((answer == 'y' || answer == 'y') && (answer != 'n' || answer !='n'));

although if you test for y, you know your only other option would be n, so why even test for n...

Also, line #57 does not need to exist, because if you fall through the do/while loop, you can assume that the user no longer wants to input data and you can just continue with the rest of the program.

This question has already been answered. Start a new discussion instead.