Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,132 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,798 people online right now. Registration is fast and FREE... Join Now!




copying string into new array

 
Reply to this topicStart new topic

copying string into new array, copying string into new array

freshman_prog
13 May, 2007 - 04:04 PM
Post #1

New D.I.C Head
*

Joined: 23 Mar, 2007
Posts: 23


My Contributions
this is my code watch in case 2 for pakistani team i want to choose team for playing i want to take all players in a new array.




CODE

#include <iostream>
#include <fstream>
#include <conio>
#include <string>
#include <iomanip>
class cric
{
protected:
int run,balls,over;
string pname,tname,desig;
public:
  cric()
  {cout<<"\t\t\tICC Rating System"<<endl;
  /*cout<<"press 1 for Australi"<<endl;
  cout<<"press 2 for Pakistan"<<endl;;
  cout<<"press 3 for India"<<endl;;
  cout<<"press 4 for Sri Lanka"<<endl;;
  cout<<"press 5 for Sauth Africa"<<endl;;
  cout<<"press 6 for New Zeland"<<endl;;
  cout<<"press 7 for West Indies"<<endl;;*/}
/////////////////////////////T E A M S////////////////////////////////////
//././././././././././././././././././/././././././././././././././/./././
  void aus()
  {
   cout <<"gerry";
  }

  void pak()
{
     int i,j;
      char str1[15][44],x;
     cout<<setw(17)<<"NAME OF PLAYER"<<setw(16)<<"Match Palyed"<<setw(13)<<"TOTAL runs"<<setw(7)<<"AVG"<<setw(15)<<"Hiegest score"<<setw(11)<<"S.rate\n\n";

    cout<<"1: imran Nazir   "<<endl;
    cout<<"2: imran Farhat\n";
    cout<<"3: Muhammad Yosuf\n";
    cout<<"4: Fawad Alam\n";
    cout<<"5: Asim Kamal\n";
    cout<<"6: Shoib Malik\n";
    cout<<"7: Kamran Akmal\n";
    cout<<"8: Muhammad Hafiz\n";
    cout<<"9: Shoib Akhtar\n";
    cout<<"10:Muhammad Asif\n";
    cout<<"11:Salman Butt\n";
    cout<<"12:Danish Kaneria\n";
    cout<<"13:Rao Iftikhar\n";
    cout<<"14:Najaf Shah\n";
    cout<<"15:Shahid Afridi\n\n\n\n";
    cout<<"Select players by using there sr.#";
   // char str[]="Imran Nazir";



    switch(x)
    {
     case '1':strcpy(str1[j],"Imran Nazir");break;
    case '2':strcpy(str1[j],"imran Farhat");break;
    case '3':strcpy(str1[j],"Muhammad Yosuf");break;
    case '4':strcpy(str1[j],"Fawad Alam");break;
    case '5':strcpy(str1[j],"Asim Kamal");break;
    case '6':strcpy(str1[j],"SHoib Malik");break;
    case '7':strcpy(str1[j],"Muhammad asif");break;
    case '8':strcpy(str1[j],"Kamran Akmal");break;
    case '9':strcpy(str1[j],"Shoib Akhtar");break;
    case '10':strcpy(str1[j],"imran Farhat");break;
    case '11':strcpy(str1[j],"imran Farhat");break;
    case '12':strcpy(str1[j],"imran Farhat");break;

    };
  //  for (int i=0;i<3;i++){
  //cout<<str1[0];
  //cout<<str1[1];


   for (i=0;i<11;i++)
  {
    cin>>x;}

    for (j=0;j<10;j++)

    cout<<str1[j];


       }
  void ind()
   {
     cout<<"dravid";
   }
  void sl()
  {}
  void sa()
  {}
  void nz()
  {}
  void wi()
  {}
float ag()
{int mp=50,tr=500;
float avg;
avg=mp%tr;
return(avg);
}

  void selectteam()
   {
   char a;
  cout<<"press 1 for Australia"<<endl;
  cout<<"press 2 for Pakistan"<<endl;;
  cout<<"press 3 for India"<<endl;;
  cout<<"press 4 for Sri Lanka"<<endl;;
  cout<<"press 5 for Sauth Africa"<<endl;;
  cout<<"press 6 for New Zeland"<<endl;;
  cout<<"press 7 for West Indies"<<endl;;

  cout<<"select team   ";
  cin>>a;

   int y;
   switch(a)
    {
      case'1':cout<<"u hav selected australia"<<endl
      <<"if u want to select players press: 1"<<endl<<endl<<"use old team press 2:";
      cin>>y;
      if(y!=1)
          cout<<"ot";
       else aus();

      break;
      case'2':cout<<"u hav selected Pakistan"<<endl
      <<"if u want to select players press: 1"<<endl<<endl<<"use old team press 2:";
      cin>>y;
      if(y!=1)
          cout<<"ot";
       else pak      ();;
       break;
      case'3':cout<<"u hav selected India"<<endl
      <<"if u want to select players press: 1"<<endl<<endl<<"use old team press 2:";
      cin>>y;
      if(y!=1)
          cout<<"old team";
       else ind();
      break;
      case'4':cout<<"u hav selected Sri Lanka"<<endl
      <<"if u want to select players press: 1"<<endl<<endl<<"use old team press 2:";
      cin>>y;
      if(y!=1)
          cout<<"ot";
       else sl();
      break;
      case'5':cout<<"u hav selected Sauth Africa"<<endl
      <<"if u want to select players press: 1"<<endl<<endl<<"use old team press 2:";
      cin>>y;
      if(y!=1)
          cout<<"ot";
       else sa();
      break;
      case'6':cout<<"u hav selected new Zealand"<<endl
      <<"if u want to select players press: 1"<<endl<<endl<<"use old team press 2:";
      cin>>y;
      if(y!=1)
          cout<<"ot";
       else nz();
      break;
      case'7':cout<<"u hav selected West Indies"<<endl
      <<"if u want to select players press: 1"<<endl<<endl<<"use old team press 2:";
      cin>>y;
      if(y!=1)
          cout<<"ot";
       else wi();
      break;
    }
    }
};
   main()
   { cric a,b;

   a.selectteam();
   getch();
   }

User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Copying String Into New Array
14 May, 2007 - 03:36 AM
Post #2

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,025



Thanked: 35 times
Dream Kudos: 125
My Contributions
cut that switch for x and paste it inside :

CODE

for (i=0;i<11;i++)
  {
    cin>>x;
  }


after cin.

so it will look like.
CODE

for (i=0;i<11;i++)
  {
    cin>>x;
    switch(x)
    {
     case '1':strcpy(str1[i],"Imran Nazir");break;
    case '2':strcpy(str1[i],"imran Farhat");break;
    case '3':strcpy(str1[i],"Muhammad Yosuf");break;
    case '4':strcpy(str1[i],"Fawad Alam");break;
    case '5':strcpy(str1[i],"Asim Kamal");break;
    case '6':strcpy(str1[i],"SHoib Malik");break;
    case '7':strcpy(str1[i],"Muhammad asif");break;
    case '8':strcpy(str1[i],"Kamran Akmal");break;
    case '9':strcpy(str1[i],"Shoib Akhtar");break;
    case '10':strcpy(str1[i],"imran Farhat");break;
    case '11':strcpy(str1[i],"imran Farhat");break;
    case '12':strcpy(str1[i],"imran Farhat");break;

    };
  }



everything else seems ok for me.
hope this will help you. smile.gif
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:23PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month