What's new

Closed C++ array

Status
Not open for further replies.

alchemist_19

Addict
Joined
Oct 8, 2018
Posts
50
Reaction
3
Points
77
#include <iostream>
using namespace std;
int main(int argc, char** argv){
int b=0,c=0;
char rep;
cout<<"How many User? ";
cin>>b;
string arr;
string search="";
for(int a=0; a<b; a++)
{
cout<<"Name" <<endl;
cin>> arr[a];
system("cls");
}
do
{
cout<<"Name\n";
for(int a=0; a<b; a++)
{
cout<<arr[a] <<endl;
}
cout<<"\na(add)\nd (Delete)\ne (Edit)\ns (search)";
cin>>rep;
switch(rep){
case 'a':
cout<<"Name want to add: ";
cin>>search;
for(int a=0;a<b ; a++)
{
if(search!="")
{
a=b;
}
}
break;
default:
system("cls");
cout<<"a (add)\nd (Delete)\ne (Edit)\ns (search)";
}
cout<<"\nAgain? y/n";
cin>>rep;
system("cls");
}
while(rep=='y');
for(int a=0; a<b; a++)
{
cout<<arr[a] <<endl;
}
return 0;
}

Paano mag add ng user?
Halimbawa 2 user ang nilagay ko at gusto kong dagdagan ng isa pang user, bale 3 user ang e print nya.
Salamat po. Newbie here.
 
ang nagawan ko na ng code ay add and view, pakitry po kung ganito ba ang want mo mangyari, hehe

Code:
#include <iostream>
#include <string>
using namespace std;
int main(){
    
    int input=0;
    int z, i;
    cout<<"How many users? ";
    cin>>input;

    string array[input];

    for (z = 0; z < input; z++) {
    cout<<"Input user # "<<(z+1)<<" --> ";
    cin >> array[z];
    cout<<endl;
    }
    
    AGAIN:
    char what;
    cout<<"Successfully inputted "<<input<<" users. \n"<<"v (VIEW)\na (ADD)\nd (DELETE)\ne (EDIT)\ns (SEARCH) \n";
    cin>>what;
    
    if(what=='v'||what=='V'){
                for (z = 0; z < input; z++) {
                cout<<"\nUser #" <<(z+1)<<" "<<array[z]<<endl;
                }
    }else if(what=='a'||what=='A'){
        
                
                
                int add=0;
                int a=0;
                cout<<"How many users you want to add more? ";
                cin>>add;
                
                string array1[input+add];
                for(int i = 0; i < input; ++i)
                {
                    array1[i] = array[i];
                }
                for (a = input; a < (input+add); a++) {
                cout<<"Input user # "<<(a+1)<<" --> ";
                cin >> array1[a];
                cout<<"";
                }
                
                for (a = 0; a < input+add; a++) {
                cout<<"\nUser #" <<(a+1)<<" "<<array1[a]<<endl;
                }
    }else{
        cout<<"Wrong input!";
        goto AGAIN;
    }
    
    


    
}
 
ang nagawan ko na ng code ay add and view, pakitry po kung ganito ba ang want mo mangyari, hehe

Code:
#include <iostream>
#include <string>
using namespace std;
int main(){
   
    int input=0;
    int z, i;
    cout<<"How many users? ";
    cin>>input;

    string array[input];

    for (z = 0; z < input; z++) {
    cout<<"Input user # "<<(z+1)<<" --> ";
    cin >> array[z];
    cout<<endl;
    }
   
    AGAIN:
    char what;
    cout<<"Successfully inputted "<<input<<" users. \n"<<"v (VIEW)\na (ADD)\nd (DELETE)\ne (EDIT)\ns (SEARCH) \n";
    cin>>what;
   
    if(what=='v'||what=='V'){
                for (z = 0; z < input; z++) {
                cout<<"\nUser #" <<(z+1)<<" "<<array[z]<<endl;
                }
    }else if(what=='a'||what=='A'){
       
               
               
                int add=0;
                int a=0;
                cout<<"How many users you want to add more? ";
                cin>>add;
               
                string array1[input+add];
                for(int i = 0; i < input; ++i)
                {
                    array1[i] = array[i];
                }
                for (a = input; a < (input+add); a++) {
                cout<<"Input user # "<<(a+1)<<" --> ";
                cin >> array1[a];
                cout<<"";
                }
               
                for (a = 0; a < input+add; a++) {
                cout<<"\nUser #" <<(a+1)<<" "<<array1[a]<<endl;
                }
    }else{
        cout<<"Wrong input!";
        goto AGAIN;
    }
   
   


   
}
Thank you, new topic namin yan array. hehe
 
Status
Not open for further replies.

Similar threads

Back
Top