Hello,
I'm working on my project "The Vending Machine Software"

Here I need to use Graphics and mouse handling.. I'm totally new into Mouse programming in C++, still doing the coding with help of some online tutorials..

What I've to do is,
Show a welcome page first when I run the project, there will be a mouse cursor, and when I click anywhere, it will bring me to the next page..

I've coded this much yet, remember project is not yet complete.. I want to go to void login function after I click anywhere on Welcome page...

The code I've done so far brings me to Login function but it disturbs all colors of the page instead of black and white..

here's video - http://www.youtube.com/watch?v=1F7hvwuw2uI

Please help me..

Here's my yet to complete Project source code..

// THE VENDING MACHINE PROJECT
// CODING BY RAHUL PATIL,
// COMPUTER SCIENCE OF ENGG,
// BVP, KOLHAPUR
/////////////////////////////////

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<graphics.h>
#include<dos.h>

union REGS in, out;

class vm
{
	  int ch,choice;       //declaration of choices
	  int rc,rt,qty;       //rate of coffee, rate of tea, and quantity
	  int temptot,rate;    //total, and rate of the product
	  int tot;
	  int limit,salary;    //limit as per employee's salary
	  char *prod,ch1;      //value to pass in display or receipt module

	public:
	  vm()
	  {
	  rt=10;               //rate of tea
	  rc=20;               //rate of coffee
	  }
	  void buy(int);
	  void save();
	  void disp(int);
};


void vm::buy(int x)
{
   tot=0;
   temptot=0;
   limit=x*0.1;
   cout<<"\n\n\tWhat would you like to buy?";
   cout<<"\n\t1.Coffee\n\t2.Tea\n\t3.Exit";
   cin>>ch;
   switch(ch)
   {
     case 1:
      cout<<"\n\tHow many quantity you want to buy?";
      cin>>qty;
      temptot=temptot+(qty*rc);
      if(temptot>limit)
      {
      cout<<"\n\n\tSorry, you can't purchase this product..\n";
      cout<<"\n\tYou've crossed monthly expense limit..";
      }
      else
      {
      tot=tot+(rc*qty);
      limit=limit-tot;
      cout<<"\n\tDear Member,";
      cout<<"Thank you for purchasing tea..";
      cout<<"Please wait for receipt\n\n\n";
      save();
      disp(1);
      }
      break;

     case 2:
      start:
      cout<<"\n\tHow many quantity you want to buy?";
      cin>>qty;
      temptot=temptot+(qty*rt);
      if(temptot>limit)
      {
      cout<<"\n\n\tSorry, you can't purchase this product..\n";
      cout<<"\n\tYou've crossed monthly expense limit..";
      }
      else
      {
      tot=tot+(rt*qty);
      cout<<"\n\tDear Member,";
      cout<<"Thank you for purchasing tea..";
      cout<<"\nPlease wait for receipt\n\n\n";

      save();
      disp(2);

      }
      break;

     case 3:
      exit(0);
   }

}

void vm::save()
{
	cout<<"\n\n\tData successfully saved into file...\n\n\n\n";
}

void vm::disp(int x)
{
      if(x==1)
      {
      prod="Coffee";
      rate=20;
      }
      else
      {
      rate=10;
      prod="Tea";
      }
      cout<<"\n\n\t***Purchase receipt***\n\n";
      cout<<"\n\tProduct\tRate\tQty\tTotal";
      cout<<"\n\t-----------------------------";
      cout<<"\n\t"<<prod<<"\t"<<rate<<"\t"<<qty<<"\t"<<tot;
      cout<<"\n\n\tAvailable Balance: Rs "<<limit;
}

void login()
{
	vm user1,user2,user3,user4,user5;             //Employee as object
	int ch;
	int s1=2000,s2=3000,s3=4000,s4=3500,s5=2500;  //User salaries
	clrscr();

	cout<<"\n\n\tAs what user you want to login?\n\t";
	cout<<"[Answer should be in form of 1,2,3,4,5 only] : ";
	cin>>ch;

	if(ch==1)
	user1.buy(s1);
	else if(ch==2)
	user2.buy(s2);
	else if(ch==3)
	user3.buy(s3);
	else if(ch==4)
	user4.buy(s4);
	else if(ch==5)
	user5.buy(s5);
	else
	cout<<"\n\n\tInvalid user..\n";
}

void main()
{
   int gdriver = DETECT, gmode, errorcode;
   initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

// The Welcome Page

   setcolor(1);
   setbkcolor(13);
   settextstyle(1,HORIZ_DIR,1);
   outtextxy(50,20,"BHARATI VIDYAPEETH'S COLLEGE OF ENGINEERIG, KOLHAPUR");
   settextstyle(3,HORIZ_DIR,4);
   outtextxy(70,100,"THE VENDING MACHINE SOFTWARE");
   settextstyle(0,HORIZ_DIR,1);
   outtextxy(50,195,"Project by : ");
   outtextxy(50,205,"1.Rahul Patil      SECSE35 ");
   outtextxy(50,215,"2.Sambhaji More    SECSE28 ");
   outtextxy(50,225,"3.Ashish Nagdev    SECSE30 ");
   outtextxy(50,235,"4.Priyanka Kumbhar SECSE22 ");
   outtextxy(50,245,"5.Sharayu Mane     SECSE26 ");
   settextstyle(3,HORIZ_DIR,1);
   outtextxy(50,310,"Under the Guidance of : MR. PATRAVALE A.M.");
   settextstyle(0,HORIZ_DIR,1);
   outtextxy(50,430,"Dept. of Computer Science and Engineering");

// Mouse integration and detection
     in.x.ax = 0;
     int86 (0X33,&in,&out);

     in.x.ax = 1;
     int86 (0X33,&in,&out);

   //Detect
    while(!kbhit())
	 {
	  in.x.ax=3;
	  int86 (0X33,&in,&out);
	  if(out.x.bx==1)
	  login(); //this is where I want to go..
	 }

   getch();
   closegraph();

	getch();
}

Here I need to use Graphics and mouse handling.. I'm totally new into Mouse programming in C++, still doing the coding with help of some online tutorials..

This is a question that seemed fairly easy to answer until I then looked at your code.

I take it that you are using an old version c++.

If not your OS is a graphical system such as windows. And you should use their built in handling of graphics for the mouse, etc.
and let us know.

Without it you need to be able to detect when the mouse button is clicked which probably requires interfacing with the mouse drivers which will get messy ...

You can still OO so that use say an unused char input to act as the mouse click for navigation to get that part working and then I am sure who ever set this task has told you how to access the mouse clicks.

Hmm, Our Education system is not that well to teach new C++ with advanced coding.. They still prefer crappy old languages..

I've solved the problem by adding statement

closegraph();

before going to the

login();

function...

thanks for the good reply tetron.

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.