0

Hi !!! I am doing a first C++ program, the way is getting the best choice between choices by comparison, here is my code

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
int main()
{
int i,n,m,k,j,tem,te;
struct ways
{
char w[20];
} myArray[15],temp;
int a[8]={0};
int b[8]={0};
textbackground(1);
textcolor(15);
cout << "How many ways ?";
cin >> k;
for (i=1; i<=k; i++)
    {
    printf("Way %d:",i);
    scanf("%s",&myArray[i].w);
    printf("\n");
    }
printf("Your ways listed here:\n");
for (i=1; i<=k; i++)
    {
    printf("\t%d.%s\n",i,&myArray[i].w);
    }
getch();
printf("Compare each different couple of ways\n");
 for (i=1;i<=k;i++)
   for (j=i+1;j<=k;j++)
   {
   printf("\nBetween : %s",&myArray[i].w);
   printf("\nAnd : %s",&myArray[j].w);
   printf("\nYour rate : ");
   scanf("%d",&m);
   printf(" / ");
   scanf("%d",&n);
   b[i]=b[i]+m-n;
   b[j]=b[j]+n-m;
   if (m>n)
      a[i]=a[i]+3;
   if (m==n)
    {
      a[i]=a[i]+1;
      a[j]=a[j]+1;
    }
   if (m<n)
      a[j]=a[j]+3;
   }
   for (i=1;i<=k;i++)
   for (j=i+1;j<=k;j++)
   {
   if ((a[i]<a[j]) || ((a[i]==a[j]) && (b[i]<b[j])))
    {
      &temp.w=&myArray[i].w;
      &myArray[i].w=&myArray[j].w;
      &myArray[j].w=&temp.w;
      tem=a[i];
      a[i]=a[j];
      a[j]=tem;
      te=b[i];
      b[i]=b[j];
      b[j]=te;
    }
   }
   for (i=0;i<=k;i++)
   {
   printf("\n%s",&myArray[i].w);
   printf("\t%d",a[i]);
   printf("\t%d",b[i]);
   }
getch();
clrscr();
return 0;
}

The errors is in red code, could you explain me why I got that errors ?
Thanks :)

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by smiles
0

c-style character arrays can not be copied like you are attempting to do in lines 56-58. You have to use strcpy() to do that

strcpy(temp.w,myArray[i].w);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.