library management program

adding loop statement

Page 1 of 1

14 Replies - 3235 Views - Last Post: 12 June 2010 - 07:26 AM Rate Topic: -----

#1 skaloee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-June 10

library management program

Posted 12 June 2010 - 02:41 AM

hello..i have problem adding 'while loop' statement in my program..these are my program:
#include <iostream.h>
#include <stdlib.h>

int Main();
int a,b,c,d,e,f;
int Pin();
int Menu();
int report();
int journal();
int text();
int Exit();
int number,num,choice;
int pin;
void main()
{
	Main();
	Pin();
	Menu();
	report();
	journal();
	text();
	Exit();
}

int Main()
{
	cout<<endl;
	cout<<" WELCOME TO SKALOE LIBRARY"<<endl;
	cout<<"							 "<<endl;
	cout<<"                          "<<endl;
	cout<<"  (1)Enter password       "<<endl;
	cout<<"  (2)Exit operation       "<<endl;
	cout<<"                          "<<endl;
	cout<<"                          "<<endl;

	cout<<"Please enter your choose menu:";
	cin>>number;
	
	system("cls");
	if(number==1)
	{
		Pin();
	}
	else if(number==2)
	{
		system("cls");
		cout<<endl;
		cout<<" Thank you "<<endl;
		
		cout<<endl;
		Exit();

	}

	else
	{
		Main();
	}
	return 0;

}
int Pin()
{
	cout<<endl;
	cout<<" Enter password "<<endl;
	cout<<"______________________"<<endl;
	cout<<endl;
	cout<<" Pin: "<<endl;

	cin>>pin;
	system("cls");
	if(pin==123)
	{
		Menu();
	}
	else
	{
		cout<<" invalid password "<<endl;
		cout<<" Please try again "<<endl;
		cout<<endl;

		system("pause");
		system("cls");
		Main();
	}
	return 0;
}

int Menu()
{
	cout<<endl;
	cout<<"*** (1) report       ***"<<endl;
	cout<<"*** (2) journal      ***"<<endl;
	cout<<"*** (3) text         ***"<<endl;
	cout<<"*** (4) Exit         ***"<<endl;

	cout<<endl;

	cout<<"Please choose:  ";
	cin>>num;

	system("cls");

	if(num==1)
	{
		report();
	}
	else if(num==2)
	{
		journal();
	}
	else if(num==3)
	{
		text();
	}
	else if(num==4)

	{
		system("cls");
		cout<<endl;
		cout<<" Have a nice day "<<endl;
		cout<<" Thank your for choosing us"<<endl;
		
		cout<<endl;
		Exit();

	}

	else
	{
		cout<<endl;
		cout<<"Please enter the correct choice."<<endl;
		system("pause");
		system("cls");
		Menu();

	}

	return 0;
}

int report()
{
	cout<<"enter report title number\n";
	cin>>a;
	cout<<endl;
	cout<<"author number\n";
	cin>>b;
	cout<<endl;
	cout<<"your request is being prosessed...\n";
	cout<<endl;
	cout<<"please proceed to the counter to collect your requested report";
	cout<<endl;
	cout<<endl;
	cout<<"select choise below\n";
	cout<<"(1) Menu"<<endl;
	cout<<"(2) Exit"<<endl;

	cin>>choice;

	if(choice==1)
	{
		Menu();
	}

	else if(choice==2)

	{
		system("cls");
		cout<<endl;
		cout<<" Have a nice day "<<endl;
		cout<<" Thank your for choosing us"<<endl;
		
		cout<<endl;
	Exit();

	}

	else 
		{
		cout<<endl;
		cout<<" enter choice."<<endl;
		system("pause");
		system("cls");
		report();

	}

	return 0;

}

int journal()

{
	cout<<"enter journal title number\n";
	cin>>c;
	cout<<endl;
	cout<<"author number\n";
	cin>>d;
	cout<<endl;
	cout<<"your request is being prosessed...\n";
	cout<<endl;
	cout<<"please proceed to the counter to collect your requested report";
	cout<<endl;
	cout<<endl;
	cout<<"select choise below\n";
	cout<<"(1) Menu"<<endl;
	cout<<"(2) Exit"<<endl;

	cin>>choice;

	if(choice==1)
	{
		Menu();
	}

	else if(choice==2)

{
		system("cls");
		cout<<endl;
		cout<<"	Thank you "<<endl;
		
		cout<<endl;
Exit();


	}

	else

		{
		cout<<endl;
		cout<<"Please enter the correct choice."<<endl;
		system("pause");
		system("cls");
		journal();

	}

	return 0;

}

int text()
{
	cout<<"enter text title number\n";
	cin>>e;
	cout<<endl;
	cout<<"author number\n";
	cin>>f;
	cout<<endl;
	cout<<"your request is being prosessed...\n";
	cout<<endl;
	cout<<"please proceed to the counter to collect your requested report";
	cout<<endl;
	cout<<endl;
	cout<<"select choise below\n";
	cout<<"(1) Menu"<<endl;
	cout<<"(2) Exit"<<endl;

	cin>>choice;

	if(choice==1)
	{	Menu();
	}

	else if(choice==2)

		{
		system("cls");
		cout<<endl;
		cout<<"Have a nice day "<<endl;
		cout<<"	Thank you for choosing us"<<endl;
		
		cout<<endl;
Exit();


	}

	else

		{
		cout<<endl;
		cout<<"Please enter the correct choice."<<endl;
		system("pause");
		system("cls");
		text();
	}
	return 0;
}

int Exit()
{
	Exit();
	system("cls");
	return 0;
}



guys..any idea?? i'm a newbie here..

Is This A Good Question/Topic? 0
  • +

Replies To: library management program

#2 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 162
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: library management program

Posted 12 June 2010 - 03:03 AM

Check the comments.
int Exit()
{
        Exit();  //This will cause an infinite recursion.
        system("cls");
        return 0;
}



I suggest using a do-while loop for displaying your menu, rather than using recursion.
int choice=0;
do
{
...//Show your menu here
}
while(choice!=2); //Assuming choice 2 is for exit



And using switch structure makes the program even better.
int choice=0;
do
{
   ... //Show the menu

   cin>>choice;
   switch(choice)
   {
     case 1: //do something
     break;
     case 2:
     break;
     default: cout<<"Wrong choice\n";
   }
   ... //Clear screen
}
while(choice!=2);


Was This Post Helpful? 1
  • +
  • -

#3 skaloee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-June 10

Re: library management program

Posted 12 June 2010 - 03:06 AM

owww...okay i'll try it..thanks munawar for helping me..
Was This Post Helpful? 0
  • +
  • -

#4 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 965
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: library management program

Posted 12 June 2010 - 03:14 AM

Also, void main() is WRONG. Use int main().
Was This Post Helpful? 1
  • +
  • -

#5 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: library management program

Posted 12 June 2010 - 03:31 AM

I see what you are trying to do here:
void main()
{
        Main();
        ...
}

int Main()
{


but it is a terribly bad idea.

You can get away with relying on case sensitivity to tell the difference between the real "main()" (which should be "int main()" not "void main)) and the fake "Main()".

On the void main() issue read here the words of the man who invented C++:
http://www.research.....html#void-main
Can I write "void main()"?
The definition
void main() { /* ... */ }
is not and never has been C++, nor has it ever been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1.


What does the function you have named "Main()" do?
All it really does is present the menu to the user so a far better name would be "programMenu()" or "getUserPasswordOrQuit()" or something that describes what the function does. The names of your variables and functions should describe what they do or hold.
Really it is hard to imagine anything worse that "Main()" for that function so change it to something else, even if your choose the worst imaginable name it is hard to believe it could be worse than "Main()".
Was This Post Helpful? 2
  • +
  • -

#6 skaloee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-June 10

Re: library management program

Posted 12 June 2010 - 03:51 AM

View Postjanotte, on 12 June 2010 - 02:31 AM, said:

I see what you are trying to do here:
void main()
{
        Main();
        ...
}

int Main()
{


but it is a terribly bad idea.

You can get away with relying on case sensitivity to tell the difference between the real "main()" (which should be "int main()" not "void main)) and the fake "Main()".

On the void main() issue read here the words of the man who invented C++:
http://www.research.....html#void-main
Can I write "void main()"?
The definition
void main() { /* ... */ }
is not and never has been C++, nor has it ever been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1.


What does the function you have named "Main()" do?
All it really does is present the menu to the user so a far better name would be "programMenu()" or "getUserPasswordOrQuit()" or something that describes what the function does. The names of your variables and functions should describe what they do or hold.
Really it is hard to imagine anything worse that "Main()" for that function so change it to something else, even if your choose the worst imaginable name it is hard to believe it could be worse than "Main()".


oww...you are right..i hve already change it..urmm should i remove the "void main" or just keep it??
Was This Post Helpful? 0
  • +
  • -

#7 skaloee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-June 10

Re: library management program

Posted 12 June 2010 - 03:57 AM

View PostMunawwar, on 12 June 2010 - 02:03 AM, said:

Check the comments.
int Exit()
{
        Exit();  //This will cause an infinite recursion.
        system("cls");
        return 0;
}



I suggest using a do-while loop for displaying your menu, rather than using recursion.
int choice=0;
do
{
...//Show your menu here
}
while(choice!=2); //Assuming choice 2 is for exit



And using switch structure makes the program even better.
int choice=0;
do
{
   ... //Show the menu

   cin>>choice;
   switch(choice)
   {
     case 1: //do something
     break;
     case 2:
     break;
     default: cout<<"Wrong choice\n";
   }
   ... //Clear screen
}
while(choice!=2);


munawwar..im still not sure how to add the 'do while'..should i make new variable for it??or just fit it in the existed variable??or replace the 'if'statement??
Was This Post Helpful? 0
  • +
  • -

#8 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 854
  • View blog
  • Posts: 2,338
  • Joined: 20-August 07

Re: library management program

Posted 12 June 2010 - 03:59 AM

View Postskaloee, on 12 June 2010 - 10:51 AM, said:

oww...you are right..i hve already change it..urmm should i remove the "void main" or just keep it??

Why would you keep it? 'void main' is undefined in the C and C++ standards, so you need to change it to int main or risk your program potentially displaying unusual behaviour
Was This Post Helpful? 0
  • +
  • -

#9 skaloee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-June 10

Re: library management program

Posted 12 June 2010 - 04:12 AM

View PostBench, on 12 June 2010 - 02:59 AM, said:

View Postskaloee, on 12 June 2010 - 10:51 AM, said:

oww...you are right..i hve already change it..urmm should i remove the "void main" or just keep it??

Why would you keep it? 'void main' is undefined in the C and C++ standards, so you need to change it to int main or risk your program potentially displaying unusual behaviour

thanks..
Was This Post Helpful? 0
  • +
  • -

#10 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 162
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: library management program

Posted 12 June 2010 - 04:30 AM

View Postskaloee, on 12 June 2010 - 01:57 PM, said:

munawwar..im still not sure how to add the 'do while'..should i make new variable for it??or just fit it in the existed variable??or replace the 'if'statement??

No, you can use the variables which you already defined.
And yes, if you plan to use switch, then you won't need many of those if statements.

I also suggest that you read/revise about loops, before trying to change the code.
Was This Post Helpful? 0
  • +
  • -

#11 skaloee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-June 10

Re: library management program

Posted 12 June 2010 - 04:45 AM

View PostMunawwar, on 12 June 2010 - 03:30 AM, said:

View Postskaloee, on 12 June 2010 - 01:57 PM, said:

munawwar..im still not sure how to add the 'do while'..should i make new variable for it??or just fit it in the existed variable??or replace the 'if'statement??

No, you can use the variables which you already defined.
And yes, if you plan to use switch, then you won't need many of those if statements.

I also suggest that you read/revise about loops, before trying to change the code.

oww..okay..i think im gonna go for 'switch' statement..:)
Was This Post Helpful? 0
  • +
  • -

#12 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 162
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: library management program

Posted 12 June 2010 - 04:49 AM

I just noticed you are using <iostream.h>. This has been deprecated for more than a decade.
Use :
#include <iostream>
using namespace std;


Note that there is no '.h'.

Also while using C++, you may use
#include <cstdlib> instead of stdlib.h

I would like to know which compiler and IDE are you using, Borland 3.1?
Was This Post Helpful? 0
  • +
  • -

#13 skaloee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-June 10

Re: library management program

Posted 12 June 2010 - 05:05 AM

View PostMunawwar, on 12 June 2010 - 03:49 AM, said:

I just noticed you are using <iostream.h>. This has been deprecated for more than a decade.
Use :
#include <iostream>
using namespace std;


Note that there is no '.h'.

Also while using C++, you may use
#include <cstdlib> instead of stdlib.h

I would like to know which compiler and IDE are you using, Borland 3.1?

im using the microsoft c++ 6.0..
Was This Post Helpful? 0
  • +
  • -

#14 JITHU  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 62
  • View blog
  • Posts: 201
  • Joined: 02-July 07

Re: library management program

Posted 12 June 2010 - 06:51 AM

View Postskaloee, on 12 June 2010 - 12:05 PM, said:

im using the microsoft c++ 6.0..


I think, now it's time for you to upgrade your IDE to a modern one. So if you can, get the VC++ 2010 Express edition which is freely available to anyone.

One another interesting IDE is CodeLite.

If you think, that IDEs are really not useful for you because you're creating small applications or they slowdown you, just go with a text-editor like Notepad++ and a compiler like MinGW(on Windows) or g++(on Linux).

Advice:
Follow and write always standard C++.

This post has been edited by JITHU: 12 June 2010 - 06:57 AM

Was This Post Helpful? 0
  • +
  • -

#15 skaloee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-June 10

Re: library management program

Posted 12 June 2010 - 07:26 AM

View PostJITHU, on 12 June 2010 - 05:51 AM, said:

View Postskaloee, on 12 June 2010 - 12:05 PM, said:

im using the microsoft c++ 6.0..


I think, now it's time for you to upgrade your IDE to a modern one. So if you can, get the VC++ 2010 Express edition which is freely available to anyone.

One another interesting IDE is CodeLite.

If you think, that IDEs are really not useful for you because you're creating small applications or they slowdown you, just go with a text-editor like Notepad++ and a compiler like MinGW(on Windows) or g++(on Linux).

Advice:
Follow and write always standard C++.

yeah..i should..hehehe..thank you for the link..^_^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1