🔒 Closed Using for loop.[help]

Status
Not open for further replies.

jaimeskie24

Journeyman
Gusto ko lng po malaman kung pano gamitin ang for loop for calling a functio to objects.

i.e: case 1: Input new record
Nag input ako ng new record.
then case2: search record
paano nasave un pag search ko dpat lalabas ung ininput kong new record.
Using for loop po.
 
Kung paano masave yung first inputs kung case 1 inside a loop.
Kailangan sa labas ng loop mayroon kang dynamic array o specified size ng array or list.
Then sa case 1 kailangan mo ilagay dun yung data.
Then sa case 2, kailangan mo lang content nung array or list para mahanap yung record.
 
sinubukan ko lang.. di ko alam kung tama :D

Code:
 int menu;
            List<string> DataList = new List<string>();
           
            do
            {
                Console.Write("Choose Menu: \n 1. Insert new Data \n 2. Search Data \n 0. Exit \n Menu: ");
                menu = int.Parse(Console.ReadLine());
                switch (menu)
                {
                    case 1:
                        Console.Write("Enter Data: ");
                        string data = Console.ReadLine();
                        DataList.Add(data);
                        Console.WriteLine("Saved");
                        System.Threading.Thread.Sleep(300);
                        Console.Clear();
                        break;
                    case 2:
                        Console.Write("Search: ");
                        string input = Console.ReadLine();                       
                        int index = DataList.FindIndex(c => c == input);
                        Console.Clear();
                        Console.WriteLine("data {0} is in index {1}",input,index);
                       
                        break;
                    default:
                        break;
                }
            } while (menu != 0);
 
Step 1: Gawa ka Looping na Input Record then magsasave sa arraylist (dito pupunta yung data tinype mo)
Step 2: Gawa ka code na eh search niya dun sa arraylist (dito pupunta yung data natype mo)
tama yung sagot ni paps mrHazan pero di ko alam if anong programme language tinutukoy mo
 
QUOTE="PHC-Jeremy, post: 10215143, member: 565706"]Hindi ko gets haha[/QUOTE]
Hehe i mean po ung example ko.
sa system
"Student Database Mngt System"
Option 1 ko is mag input ng new record.
Once na mag Input ako ng new record .
then sa option 2Search Record" then lalabas ung ininput ko na new record once na sinearch ko po. :) sana ma gets mo po. Hehe nalilito kasi ako using for loop.
 
Haha pasensya napo ano po ba ung array list ? or array?
Kung paano masave yung first inputs kung case 1 inside a loop.
Kailangan sa labas ng loop mayroon kang dynamic array o specified size ng array or list.
Then sa case 1 kailangan mo ilagay dun yung data.
Then sa case 2, kailangan mo lang content nung array or list para mahanap yung record.
 
Haha pasensya napo ano po ba ung array list ? or array?
Fast example:
string names[100]; //Ito array
int nameIndex = 0;
string inputName;
string searchName;

input:
cin >> inputName;
names[nameIndex] = inputName;
nameIndex++;

search:
cin >> searchName;
for(int k = 0; k< nameIndex; k++)
{
if(searchName == names[k])
{
cout<< "Found!";
}
}
 
Status
Not open for further replies.

About this Thread

  • 14
    Replies
  • 793
    Views
  • 10
    Participants
Last reply from:
mrHazan

Online now

Members online
869
Guests online
770
Total visitors
1,639

Forum statistics

Threads
2,275,132
Posts
28,960,899
Members
1,232,634
Latest member
vcbcbcvbc
Back
Top