Syntax errors
Apr 27, 2012 at 1:10am UTC
I am getting these syntax errors and don't know why. Can someone help me out?
1>c:\users\lcmosley\documents\visual studio 2010\projects\homework7\homework7\homework7.cpp(23): error C2059: syntax error : ';'
1>c:\users\lcmosley\documents\visual studio 2010\projects\homework7\homework7\homework7.cpp(30): error C2065: 'temp' : undeclared identifier
1>c:\users\lcmosley\documents\visual studio 2010\projects\homework7\homework7\homework7.cpp(32): error C2065: 'temp' : undeclared identifier
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
void main()
{
struct {int chronum; char pname[25]; int next;} plist[50];
int n=0, i, end, maxindex;
ifstream fin;
fin.open("prez.dat" );
fin >> plist[n].pname;
while (!fin.eof())
{
plist[n].chronum = n+1;
n++;
fin >> plist[n].pname;
}
for (end=n-1; end>0; end--;)
{
maxindex = 0;
for (i=1; i<=end; i++)
{
if (strcmp(plist[i].pname, plist[maxindex].pname)>0)
maxindex=i;
temp = plist[maxindex];
plist[maxindex]=plist[end];
plist[end]=temp;
}
}
cout << i << plist[i].chronum << setw(30) << left << plist[i].pname << plist[i].next << endl;
}
Apr 27, 2012 at 1:28am UTC
Line 23: You have an extra ; in your for loop declaration.
Line 30/32: You are assigning to something called temp, but I don't see that defined anywhere.
Apr 27, 2012 at 2:10am UTC
Thanks. I am not really sure what type to declare temp?
Topic archived. No new replies allowed.