2d Array searching etc

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 423 Views - Last Post: 24 January 2013 - 06:58 AM Rate Topic: -----

#1 afortunado  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 09-November 12

2d Array searching etc

Posted 23 January 2013 - 03:40 PM

I cant get my head around this for some strange reason.
Im trying to create a database which asks the user for names and then the program saves this and they can search delete etc.
I cant seem to get ot working any help
thanks.

#include <iostream>
#include <string>
using namespace std;


void enterentry()
{

char name[256], age[256];

cout<< "Please Enter Your Name:";
cin.getline (name,256); 

cout<< "Please Enter Your Age:";
cin.getline(age,256);

cout << name << " 's Age is:"<<age;
}


void search()
{
}


void delete()
{
}

void menu()
{
cout<< " 1 - Enter New Member:"<<endl;
cout<< " 2 - Search Existing Member:"<<endl;
cout<< " 3 - Delete Member Profile:"<<endl;
}



int main()
{

	bool end =true
		while (end==true){


	menu();
	int choice;
	cin>>choice;
	if(choice==1){
		enterentry();
	else if (choice==2){
		search();
	else if (choice==3}{
		deleteentry();
	}

	cout<<"exit?"<<endl;
	cout<<"1 - yes"<<endl;
	cout<<"2 - no"<<endl;
	int exitstate;
	cin>>exitstate;
	if (exitstate==1){
		end= !end;
	}
	else if (exitstate==2){
		end==true;
	}
	else {break;}
	

cin.get();
return 0;





Is This A Good Question/Topic? 0
  • +

Replies To: 2d Array searching etc

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: 2d Array searching etc

Posted 23 January 2013 - 03:47 PM

What is actually wrong with your program? Please ask specific questions.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 afortunado  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 09-November 12

Re: 2d Array searching etc

Posted 23 January 2013 - 03:53 PM

I do not know how to get the main working so that the window displays correctly?
The code within the int main needs looking at?
Was This Post Helpful? 0
  • +
  • -

#4 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: 2d Array searching etc

Posted 23 January 2013 - 04:18 PM

View Postafortunado, on 23 January 2013 - 03:53 PM, said:

I do not know how to get the main working so that the window displays correctly?
The code within the int main needs looking at?


In C, we use structs to group together parts that make up a record - what C++ might call an object. You will need (or really want to), use code to group the parts of a record, (the record fields), into a single record or object.

Without it, your code will be a close relative of a nightmare - truly.

After you have a struct or record or object, then you will want to use an array of those structs, records, or objects, to handle all your display, edit, add or delete functions.

Here's a hint though. You don't need to actually delete, any one. You simply zero out their key value and perhaps their name, and leave the record alone. Your display function should be given logic to ignore these zeroed out records. Your Add function should know to put new records, into those zeroed out records.

What you don't want to do with a bunch of data, is be moving it around all the time. That's a huge waste of time once the database gets large, and there is always the risk of a failure that could be quite costly.

This post has been edited by Adak: 23 January 2013 - 04:19 PM

Was This Post Helpful? 0
  • +
  • -

#5 afortunado  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 09-November 12

Re: 2d Array searching etc

Posted 23 January 2013 - 04:31 PM

So your saying make a class which will include all the function names, slightly confused could you maybe demonstrate with code? thanks
Was This Post Helpful? 0
  • +
  • -

#6 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 336
  • View blog
  • Posts: 727
  • Joined: 27-June 09

Re: 2d Array searching etc

Posted 23 January 2013 - 04:35 PM

A couple things I noticed.

bool end =true

is missing a ";" at the end.

I don't think this next part is causing any issues, but it would at least be clearer to change the exit testing to
if (exitstate==1){ 
     end=false;  //was end = !end;
}  
else if (exitstate==2){  
     end=true;  //was end==true;
}  


Was This Post Helpful? 0
  • +
  • -

#7 afortunado  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 09-November 12

Re: 2d Array searching etc

Posted 23 January 2013 - 04:48 PM

it dosnt compile anything at the moment and im not sure why? It should compile the menu right?
Was This Post Helpful? 0
  • +
  • -

#8 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: 2d Array searching etc

Posted 23 January 2013 - 04:51 PM

The code you posted has several errors which need to be fixed before it will compile. Your compiler should be generating error messages. These messages tell you where the problem was detected and should describe the problem. If you don't understand your compiler error messages, post the complete message exactly as it appears in your development environment and maybe someone can help you decipher the messages.

Jim
Was This Post Helpful? 0
  • +
  • -

#9 afortunado  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 09-November 12

Re: 2d Array searching etc

Posted 23 January 2013 - 04:55 PM

Ok so heres my new main code, ive replaced the delete entry function for now.

int main()
{

	bool end =true;
	while (end==true){


	menu();
	int choice;
	cin>>choice;
	if(choice==1){
	enterentry();
	else if (choice==2){
	search();
	

	cout<<"exit?"<<endl;
	cout<<"1 - yes"<<endl;
	cout<<"2 - no"<<endl;

	int exitstate;
	cin>>exitstate;
	if (exitstate==1){
		end= false;
	}
	else if (exitstate==2){
	end=true;
	}
	else break;
	
	}
cin.get();
return 0;





im getting the follwing errors

line 52 expected a statement this is the else if (choice 2==) part
also on the same line illegal else without matching it
Was This Post Helpful? 0
  • +
  • -

#10 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: 2d Array searching etc

Posted 23 January 2013 - 04:58 PM

How can we help you if you don't post the complete code and error messages. Your error message states the problem is on line 52 but your code snippet stops at line 33.

I suggest you study this link: Control structures.


You need to post your complete program. Then cut and paste the error messages exactly as they appear in your development environment, not paraphrase them.

Jim

This post has been edited by jimblumberg: 23 January 2013 - 05:00 PM

Was This Post Helpful? 0
  • +
  • -

#11 afortunado  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 09-November 12

Re: 2d Array searching etc

Posted 23 January 2013 - 05:03 PM

#include <iostream>
#include <string>
using namespace std;


void enterentry()
{

char name[256], age[256];

cout<< "Please Enter Your Name:";
cin.getline (name,256); 

cout<< "Please Enter Your Age:";
cin.getline(age,256);

cout << name << " 's Age is:"<<age;
}


void search()
{
}



void menu()
{
cout<< " 1 - Enter New Member:"<<endl;
cout<< " 2 - Search Existing Member:"<<endl;
}



int main()
{

	bool end =true;
	while (end==true){


	menu();
	int choice;
	cin>>choice;
	if(choice==1){
	enterentry();
	else if (choice==2){
	search();
	

	cout<<"exit?"<<endl;
	cout<<"1 - yes"<<endl;
	cout<<"2 - no"<<endl;

	int exitstate;
	cin>>exitstate;
	if (exitstate==1){
		end= false;
	}
	else if (exitstate==2){
	end=true;
	}
	else break;
	
	}
cin.get();
return 0;





Ok so

line 47 = intellisense expected a statement
line 47 error = illegal else without matching if
Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: 2d Array searching etc

Posted 23 January 2013 - 05:06 PM

Compare your if statements that start on line 45 to the if statements that start on line 57, do you notice anything missing in the first set of if statements?

line 47 = intellisense expected a statement
line 47 error = illegal else without matching if 


Carefully check your brace placement thru out your program. Do you have a matching closing brace for every opening brace? Also "intellisense" is not your comiler error messages.

Jim

This post has been edited by jimblumberg: 23 January 2013 - 05:07 PM

Was This Post Helpful? 0
  • +
  • -

#13 afortunado  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 09-November 12

Re: 2d Array searching etc

Posted 23 January 2013 - 05:15 PM

Thanks alot it complies now, thanks for the advice i should always check the braces.

Just got to figure out how to search a member know, any advice :)?
Was This Post Helpful? 0
  • +
  • -

#14 afortunado  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 09-November 12

Re: 2d Array searching etc

Posted 23 January 2013 - 06:35 PM

Anyone got any idea on how i can implement a search function into this code?
Was This Post Helpful? 0
  • +
  • -

#15 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: 2d Array searching etc

Posted 23 January 2013 - 06:53 PM

I would recommend first getting your "add" function working properly. As it presently stands when your enterentry() function returns the data is lost because you aren't saving the data anywhere and the variables are local to your function.

Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2