Menu

Please Help ME ,,

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.
    Kindly check please .. The Password is guest , this is my project and i need to pass it on friday ...

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

    }

     
    • cpns

      cpns - 2008-10-06

      I did compile your code in VC++. It generates the following warnings:

      main.cpp(93) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
      main.cpp(13) : warning C4101: 'r' : unreferenced local variable

      The first requires line 93 to be:

      vat = sum * .12f;
      

      The second, either r is redundant, or you forgot to use it and teh code is incomplete perhaps.

      I even ran the code, I still have no idea what "correct" operation should be. However, beware that console stream input functions are line buffered, so when you use formatted input and expect a number, the get does not return until a whole line is entered, but only the numeric characters are processed, leaving the <newline> character buffered, so the next input sees a blank line which your code reports as "invlaid input".

      After input that does not get the whole line, you need to flush the line with:

      std::cin.ignore(std::numeric_limits<streamsize>::max(),'\n');

      (which required that <limits> is included.

      ref: http://www.augustcouncil.com/~tgibson/tutorial/iotips.html#directly

      Another observation is that you have declared:

      int link[]={'1','2','3','4','5','6','7','8','9','10'};

      which is an integer array initialised with character constants. Here:

      for(int y=0;y<=9;y++)
      {
      cout<<"\t\t"<<link[y]<<endl;
      }

      You display a list of integers, 49 for example is the decimal ASCII character code for '1', which is what is output. I doubt that that is whet you intended.

      I doubt that those are the only flaws, but it should get you moving.

      What classes should teach at this stage is debugging techniques, but few seem to bother.

      Clifford

       
    • cpns

      cpns - 2008-10-06

      Don't make us work that hard. What is the code intended to do, what does it do that is not correct. Fore example describe the expected and actual behaviour.

      Also, it seems that you have till Friday, that would be plenty of time to debug this yourself.

      Clifford

       

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.