Home Forums C Programming hi….

Viewing 8 reply threads
  • Author
    Posts
    • #2191
      MerissaQxm
      Participant

      i’m new c++….and i have jus started learnin …i’m a beginnner….
      so cud sum1 pls correct dis code….and suggest sum changes….so dat it calculates da bill even if da items r bought at random…?(…..coz now it only calculates da bill if da items r bought in an order…)

    • #3555
      GWILouisaxwzkla
      Participant

      could you post your source code?

    • #3556
      MerissaQxm
      Participant

      i know dis is da wrong way 2 b doin da program….but i’m jus a beginner….so dis is da best i cud think of….and i seriously need all da help dat i can get….plsssssssssssssss…..

      #include <iostream.h>
      #include <conio.h>
      float b=1000;
      void main()
      {
      clrscr();
      float x,b,c,amount1,amount2,amount3,p,s,j;
      float d,a,o,q,r,t,u,v,w,g,h;
      int  m;
      char choice;
      char l,Y,y,N,n;
      cout<<"nwelcome 2 my grocery store!!!!";
      cout<<"nwould u like 2 see the items available for purchase(y/n)?";
      cin>>choice;
      if(choice=='Y'||choice=='y')
      {
      cout<<"the items available are:";
      cout<<"nno."<<'t'<<"item         "<<'t'<<"quantity(b)(in grams)"<<'t'<<"m.r.p(c)";
      cout<<"n---"<<'t'<<"----         "<<'t'<<"
      <hr class="bbcode_rule" />
      "<<'t'<<"
      <hr class="bbcode_rule" />
      ";
      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<<"nwould you like 2 purchase any item?(y/n)";
      cin>>choice;
      if(choice=='Y'||choice=='y')
      {
      cout<<"nyou can purchase only two items( kindly press 'n' after purchasing two items";
      m:
      cout<<"nenter the no:of the item chosen by u";
      cin>>m;
      if(m==1)
      {
      cout<<"nenter the amount of the item  u want to purchase";
      cin>>x;
      amount1=(x*50.25)/1000.00;
      cout<<"nthe amount to be paid is:"<<amount1<<"n";
      }
      else if(m==2)
      {
      cout<<"nenter the amount of item ";
      cin>>x;
      amount2=(x*60.75)/1000.00;
      cout<<"nthe amount 2 b paid is:"<<amount2<<"n";
      }
      else if(m==3)
      {
      cout<<"nenter the amount of item";
      cin>>x;
      amount3=(x*200.00)/1000.00;
      cout<<"nthe amount 2 be paid is:"<<amount3<<"n";
      }
      cout<<"ndo u want 2 buy another item?";
      cin>>l;
      if(l=='y'||l=='Y')
      {
      goto m;
      }
      else{
      cout<<"nplease wait.... ur bill is being calculated....";
      }
      cout<<"nenter da no: of the  items u've bought in an order(enter 0 for the second item if u've bought only one item:";
      cin>>s>>j;
      if(s==1&&j==0)
      {
      o=amount1;
      cout<<"nthe total bill is:"<<o;
      }
      else if(s==1&&j==1)
      {
      p=amount1+amount1;
      cout<<"nthe total bill is:"<<p;
      }
      else if(s==1&&j==2)
      {
      q=amount1+amount2;
      cout<<"nthe total bill is:"<<q;
      }
      else if(s==1&&j==3)
      {
      r=amount1+amount3;
      cout<<"nthe total bill is:"<<r;
      }
      else if(s==2&&j==0)
      {
      a=amount2;
      cout<<"nthe total bill is:"<<a;
      }
      else if(s==2&&j==1)
      {
      t=amount2+amount1;
      cout<<"nthe total bill is:"<<t;
      }
      else if(s==2&&j==2)
      {
      u=amount2+amount2;
      cout<<"nthe total bill is:"<<u;
      }
      else if(s==2&&j==3)
      {
      v=amount2+amount3;
      cout<<"nthe total bill is:"<<v;
      }
      else if(s==3&&j==0)
      {
      w=amount3;
      cout<<"nthe total bill is:"<<w;
      }
      else if(s==3&&j==1)
      {
      g=amount3+amount1;
      cout<<"nthe total bill is:"<<g;
      }
      else if(s==3&&j==2)
      {
      h=amount3+amount2;
      cout<<"nthe total bill is:"<<h;
      }
      else if(s==3&&j==3)
      {
      d=amount3+amount3;
      cout<<"nthe total bill is:"<<d;
      }
      
      cout<<"nplease pay the requested amount";
      cout<<"nthank you.please visit again";
      }
      else if(choice=='N'||choice=='n')
      {
      cout<<"nthanks for visiting my store !!!";
      }
      }
      else if(choice=='N'||choice=='n')
      {
      cout<<"nthank you.kindly try purchasing the next time u visit the store!!!!!";
      }
      getch();
      }
    • #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();
      }

    • #3558
      GWILouisaxwzkla
      Participant

      oops. try this version with total as a double :


      #include
      #include
      #include

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

      double 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();
      }






    • #3559
      MerissaQxm
      Participant

      i divide dem all wid 1000…coz….its like….I USED DA FOLLOWIN LOGIC…
      for 1000g –> it costs Rs.100.00
      so for xg –>it should cost Rs. (100*x)/1000
      SO…must i not divide it by 1000…..?

    • #3560
      GWILouisaxwzkla
      Participant

      yeah , that makes sence :) .

    • #3561
      MerissaQxm
      Participant

      :)
      so….da program WILL give me da expected result…..rite…?

    • #3562
      GWILouisaxwzkla
      Participant

      If your original calculations are correct it should be fine. You’ll need to test the program thought…….

Viewing 8 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.