Menu

Please Help Me *Updated*

2008-10-06
2012-09-26
  • prynce comiso

    prynce comiso - 2008-10-06

    I have Problem of some part of my program , my program is working but theres something wrong.
    The output should be the one i chose in this part below should display on the on the official reciept page...this is my problem because the one i chose will not display on the last page ,
    I'm a 1st year BSIT student in the Philippines , and i dont know what should i replace..

    Example :
    What do you want: 1//i chosed 1
    T - Shirt P450//then this will appear
    You want to buy it?(Y/N)//then this will appear

         OFFICIAL RECIEPT//then this will come up
    
         ITEM                   COST//and this is next will appear
         ?????????            ?????//this part is my problem because instead it will display Item 1 which is the T - Shirt and 450 price it will display another item which you did not chose...Please help ..I appreciate your kindness..thank you.
    

    //do{
    //loop:
    //cout<<"What do you want?: ";
    //cin>>code;
    //for(int x=0;x<=9;x++)
    //{
    //-------------------------------------------------------

    include <cstdlib>

    include <iostream>

    include <string>

    include <sstream>

    using namespace std;

    int main(int argc, char *argv[])
    {
    string terminate;
    char code;
    char access;
    int r;
    int link[]={'1','2','3','4','5','6','7','8','9','10'};
    string item[10]={"T-Shirt\t","Long Pants","Wallet\t","Cap\t","Underwear","Belt\t","Bags\t","Handkerchief","Perfumes","Short Pants"};
    float sum = 0,vat = 0,vat1 = 0,mon = 0,total = 0;
    int arrays[10]={450,800,185,150,150,130,400,50,180,500};

    do{
    cout<<"Input password: ";
    getline(cin,terminate);
    }while(terminate!="guest"&&terminate!="GUEST");
    cout<<"\t\t\tITEMS LIST"<<endl;
    cout<<"\n\t\tCODE"<<endl;
    for(int y=0;y<=9;y++)
    {
    cout<<"\t\t"<<link[y]<<endl;
    }
    cout<<"Input Cash: ";
    cin>>mon;
    do{
    loop:
    cout<<"What do you want?: ";
    cin>>code;
    for(int x=0;x<=9;x++)
    {
    if(arrays[x]<=code)
    sum = sum + arrays[x];
    }
    switch(code){
    case '1':
    cout<<"ITEM - "<<item[0]<<"\t\t"<<"PRICE: P"<<arrays[0]<<endl;
    break;
    case '2':
    cout<<"ITEM - "<<item[1]<<"\t\t"<<"PRICE: P"<<arrays[1]<<endl;
    break;
    case '3':
    cout<<"ITEM - "<<item[2]<<"\t\t"<<"PRICE: P"<<arrays[2]<<endl;
    break;
    case '4':
    cout<<"ITEM - "<<item[3]<<"\t\t"<<"PRICE: P"<<arrays[3]<<endl;
    break;
    case '5':
    cout<<"ITEM - "<<item[4]<<"\t\t"<<"PRICE: P"<<arrays[4]<<endl;
    break;
    case '6':
    cout<<"ITEM - "<<item[5]<<"\t\t"<<"PRICE: P"<<arrays[5]<<endl;
    break;
    case '7':
    cout<<"ITEM - "<<item[6]<<"\t\t"<<"PRICE: P"<<arrays[6]<<endl;
    break;
    case '8':
    cout<<"ITEM - "<<item[7]<<"\t\t"<<"PRICE: P"<<arrays[7]<<endl;
    break;
    case '9':
    cout<<"ITEM - "<<item[8]<<"\t\t"<<"PRICE: P"<<arrays[8]<<endl;
    break;
    case '10':
    cout<<"ITEM - "<<item[9]<<"\t\t"<<"PRICE: P"<<arrays[9]<<endl;
    break;
    default:
    cout<<"INVALID INPUT !!"<<endl;
    break;
    }
    cout<<"You want to buy it?(Y/N)";
    cin>>access;
    switch(access){
    case 'N':
    case 'n':
    goto loop;
    default:
    cout<<"INVALID INPUT"<<endl;
    }
    }while(access!='Y'&&access!='y');
    cout<<"\nOFFICIAL RECIEPT\n"<<endl;
    cout<<"\t\tItems\t\t\t"<<"Cost"<<endl;
    for(int y = 0;y<=9;y++)
    {
    if(arrays[y]<=link[y])
    cout<<"\t\t"<<item[y]<<"\t\t"<<arrays[y]<<endl;
    }
    total = mon - sum;
    vat = sum * .12;
    vat1 = sum - vat;
    cout<<"VAT :"<<vat1<<endl;
    cout<<"NON VAT :"<<'0'<<endl;
    cout<<"12% VAT :"<<vat<<endl;
    cout<<"TOTAL COST:"<<sum<<endl;
    cout<<"CASH :"<<mon<<endl;
    cout<<"CHANGE :"<<total<<endl;
    for(int z=0;z<=9;z++)
    {
    cout<<link[z]<<endl;
    }
    system("PAUSE");
    return EXIT_SUCCESS;
    }

     
    • cpns

      cpns - 2008-10-06

      What was wrong with continuing this conversation on the thread you already started? You are likley to cause confusion.

      I posted an answer there, this code still has the same error, link[] should be a char array, not an int array. I am not sure if this is your problem.

      Rather than transcribe (inaccurately) the program output, why don't you just copy & paste it directly. The "and this line next" comments are unnecessary, we understand the concept of console line output!

      When I run your code as posted, it does not output what you say it does, or behave how you say it does. I cannot reproduce your problem, but there are problems!

      My guess is that teh code you have posted is not teh code you are running.

      Regarding teh code you did poste, why would this condition:

      > if(arrays[y]<=link[y])

      ever be true, given how they are initialised? Moreover why is arrays[] called that and not price[] for example? And I have no idea what link[] represents. It helps to use usefully names variables.

      You should also be shot for using a "goto" in this code. No one should have even mentioned to you that the language even supports it. Forget you ever knew that. In this case the code path will be identical if you simple replaced the goto with a break, so I don't know why you thought it appropriate in this case.

      At the prompt: "You want to buy it?(Y/N)", the only difference between answering Y to N is that Y displays "INVALID INPUT !!". Why? That is not what you described, but that is what the posted code does. It looks identical to teh code in teh proevious thread.

      And please stick to one thread or the other!

      Clifford

       
    • prynce comiso

      prynce comiso - 2008-10-06

      DISREGUARD THIS PART THANK YOU.
      //do{
      //loop:
      //cout<<"What do you want?: ";
      //cin>>code;
      //for(int x=0;x<=9;x++)
      //{
      //-------------------------------------------------------

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.