having problems with the editing of a function, it works to a point, but for some reason when you enter a number ( that should be correct) it comes with invaid option then on pressing return, it then outputs the fields, but all jumbled up. can any1 help me with this please ta

void editRec(cust customers[], int &row)
{
	clrscr();
	
	int number;
	int custn = 0;
	boolean found = false;
	cout << "Enter Customer Number to query : " ;
	Input(custn);
	for ( int i=0;i<row;i++ )
	{
		if (custn == customers[i].custno)
		{ 
			boolean found = true;
			cout << "Record Found:\n"
				<<"1\tCustomer No		:"<<customers[i].custno <<endl
				<<"2\tCust Name		:"<<customers[i].custname << endl
				<<"3\tStreet		:"<<customers[i].custstreet << endl
				<<"4\tTown			:"<<customers[i].custtown << endl
				<<"5\tPostcode		:"<<customers[i].custpcode << endl
				<<"6\tArea Code		:"<<customers[i].custacode << endl
				<<"7\tPhone No		:"<<customers[i].custphone << endl
				<<"8\tTotal			:"<<customers[i].totsale << endl
				<<"9\tCredit		:"<<customers[i].climit <<endl
				<<"0\tBalance		:"<<customers[i].cbalance <<endl;
			cout << "\n\nEnter number of field to be Edited:";
			Input(number);
			switch (number)
			{
			case 1: clrscr();
				do
				{
					cout << "\n\nPlease Enter Customers Number  : ";
					Input (customers[i].custno);
				}
				while (customers[i].custno < 1 || customers[i].custno > 500);
				cout << "\nThe Record Has been Updated";
				pressKey();
                break;
			case 2:  clrscr();
				cout << "\n\nPlease Enter Customers Name   : ";
				Input (customers[i].custname,31);
				cout << "\nThe Record Has been Updated";
				pressKey();
				break;
			case 3: clrscr();
				cout << "\n\nPlease Enter Customers Street   : ";
				Input (customers[i].custstreet,26);
				cout << "\nThe Record Has been Updated";
				pressKey();
				break;
			case 4:  clrscr();
				cout << "\n\nPlease Enter Customers Town   : ";
				Input (customers[i].custtown,17);
				cout << "\nThe Record Has been Updated";
				pressKey();
				break;
			case 5:  clrscr();
				cout << "\n\nPlease Enter Customers Postcode   : ";
				Input (customers[i].custpcode,9);
				cout << "\nThe Record Has been Updated";
				pressKey();
				break;
			case 6:	clrscr();
				cout << "\n\nPlease Enter Customers Phone code  : ";
				Input (customers[i].custacode,6);
				cout << "\nThe Record Has been Updated";
				pressKey();
				break;
			case 7:	clrscr();
				cout << "\n\nPlease Enter Customers Phone Number  : ";
				Input (customers[i].custphone,7);
				cout << "\nThe Record Has been Updated";
				pressKey();
				break;
			case 8:	clrscr();
				cout << "\n\nPlease Enter Customers Total Sales ex VAT : ";
				Input (customers[i].totsale);
				cout << "\nThe Record Has been Updated";
				pressKey();
				break;
			case 9:	do
					{
						clrscr();
						cout << "\n\nPlease Enter Customers Credit Limit  : ";
						Input (customers[i].climit);
					}
					while (customers[i].climit < 0.00 || customers[i].climit > 9999.99);
					cout << "\nThe Record Has been Updated";
					pressKey();
					break;
			case 0:	clrscr();
				cout << "\n\nPlease Enter Customers Current Balance  : ";
				Input (customers[i].cbalance);
				cout << "\nThe Record Has been Updated";
				pressKey();
				break;
			}
				if (found == false )
				cout << "No records were found for this number\n";

		}
	else
		errorMsg("Invalid Option");

	}
}

sure would be nice if you used syntax highlighting, so it would keep the whitespace/indentations, then i could read the code. otherwise, im not in a position now to compile it so i can't (won't) do much else.

[code=cpp] //enter your tabbed/indented c++ code here

[/code]


.

for ( int i=0;i<row;i++ )
{
      if (custn == customers[i].custno)
     { 
<snip>
     }
     else
          errorMsg("Invalid Option");

}

It would appear the logic is wrong. Unless the very first item in the array is always the custn its looking for then the program will always display the error message.

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.