Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 1st, 2006, 12:44 AM   #1
physicist
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 146
Rep Power: 3 physicist is on a distinguished road
primary expression, token } ????

**********DISCLAIMER*******************
I know that DaWei and others have told me to do my own research. I did, and learned a lot of what is in this program. But there are three errors that turned up irrelevant google search results, which no C++ error database had and which i simply do not understand. my books dont tell me about compiler errors either, so i am asking for your help
****************************************
this is my 4th program, its for the chess team at my school
when i compile this program
/////////////////////////////


///////////////////////////////

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>

using namespace std;
int newratingsame(int ro, int s, int rop);
int newratingdiffr(int ro, int s, int rop);
int newratingdiffp(int ro, int s, int rop);
void initdisplay();
void secdisplay();
int main()
{
    string b,c,d,e,f,g,h;
    int a, ro, s, rop;
    initdisplay();
    cin >>a;
    if (a == 1)
    {
          cout <<"Name of new player (no spaces):";
          getline (cin,b);
          c=b+"ratings.txt";
          ofstream myfile3("namelist.txt");
          myfile3 <<b <<"\n";
          ofstream myfile2(c.c_str());
          d="1200";
          myfile2 <<d;
          cout <<"Player added successfully, press enter to continue:";
          system("PAUSE");
          initdisplay();
    }
    if (a == 2)
    {
          int ab,pa,pb;
          secdisplay();
          cin >>ab;
          if(ab==1)
          {
           string i,ia,is,ias;
           int ans,ansa;
           ifstream myfile4("namelist.txt");
               while (! myfile4.eof() )
                    {
                     getline (myfile4,e);
                     cout << e << endl;
                    }
               cout<<"Player 1's NAME:";
               getline (cin, i);
               i=i+"ratings.txt";
               ifstream myfile7(i.c_str());
               cout<<"Player 2's NAME:";
               getline (cin, ia);
               ia=ia+"ratings.txt";
               ifstream myfile6(ia.c_str());      
               while (! myfile7.eof() )
                    {
                     getline (myfile7,is);
                     cout << is << endl;
                    }
               while (! myfile6.eof() )
                    {
                     getline (myfile6,ias);
                     cout << ias << endl;
                    }
               cout <<"\nenter P1 original rating (see above):";
               cin >>pa;
               cout <<"\nenter P2 rating (see above):";
               cin >>pb;
               
               //player 1
               cout <<"did P1 win (1) lose(-1) or draw(0); enter correct number:";
               cin >>s;
               ans=newratingsame(pa,s,pb);
               ofstream myfile8(i.c_str());
               myfile8 <<ans;
               //player2
               cout <<"did P2 win (1) lose(-1) or draw(0); enter correct number:";
               cin >>s;
               ansa=newratingsame(pb,s,pa);
               ofstream myfile9(ia.c_str());
               myfile9 <<ansa;
               cout <<"done";
               system("PAUSE");
               initdisplay();
               
         
    }
    if (a == 3)
    {
          ifstream myfile4("namelist.txt");
               while (! myfile4.eof() )
                    {
                     getline (myfile4,e);
                     cout << e << endl;
                    }
          cout << "Enter name of player whose rating you want to see:";
          getline (cin,f);          
          g=f+"ratings.txt";
          ifstream myfile5(g.c_str()); 
              while (! myfile5.eof() )
                    {
                     getline (myfile5,h);
                     cout << h << endl;
                    }
          initdisplay();
    }
    if (a ==4)
    {system("PAUSE");}
    system("PAUSE");
    return 0;
}
    void initdisplay()
    {
         cout << "////////////////////////////////////\n";
         cout << "Chess Rating Manager v1.0\n";
         cout << "Sreenath Pillai\n";
         cout << "////////////////////////////////////\n\n\n\n";
         cout << "[1] Add Player\n";
         cout << "[2] Score Game\n";
         cout << "[3] Check Ratings\n";   
         cout << "[4] Quit\n";
         cout << "\n\nChoose:";
    }   
    void secdisplay()
    {
         cout << "\n\n[1] both players rated OR both players provisional\n";
         cout << "[2] one player rated and one player provisional\n"; 
         cout << "[3] Back";
         cout << "\n\nChoose:";
    }              
    int newratingsame(int ro, int s, int rop)
        {
              return (ro + (s*21) + ((rop-ro)/25));
        }
    int newratingdiffr(int ro, int s, int rop)
        {
              return (ro + (s*6) + ((rop-ro)/100));
        }
    int newratingdiffp(int ro, int s, int rop)
        {
              return ((.8*ro) + (.2*rop) + (s*80);
        }
it gives me these errors
(everything in int main is fine)
after int main,
starting with the void initdisplay, i get errors that say the following:
Quote:
Originally Posted by dev-c++compiler
117 C:\Dev-Cpp\new.cpp expected primary-expression before "void"
117 C:\Dev-Cpp\new.cpp expected `;' before "void"
129 C:\Dev-Cpp\new.cpp expected primary-expression before "void"
129 C:\Dev-Cpp\new.cpp expected `;' before "void"
137 C:\Dev-Cpp\new.cpp a function-definition is not allowed here before '{' token
137 C:\Dev-Cpp\new.cpp expected `,' or `;' before '{' token
141 C:\Dev-Cpp\new.cpp a function-definition is not allowed here before '{' token
141 C:\Dev-Cpp\new.cpp expected `,' or `;' before '{' token
145 C:\Dev-Cpp\new.cpp a function-definition is not allowed here before '{' token
145 C:\Dev-Cpp\new.cpp expected `,' or `;' before '{' token
147 C:\Dev-Cpp\new.cpp expected `}' at end of input
so really most of it is right except there are 2 types of errors, one about the ; and } and token; and the other about the 'expected primary expression' which i thought i had....i dont understand what is wrong i declared function prototype and used them in the program then said what they do after int main
im really frustrated the code should work
of course i whipped this off in under an hour so there could easily be something i just missed
idk, please help me!!! im sorry i really tried to solve it but i have no idea and i DID try research maybe some one could tell me a good place to research (not google, im not that dumb, i tried that, i tried wiki, MSDN help, devshed help, other forums, etc)
i spent more time research than making the program! :mad:
physicist is offline   Reply With Quote
Old Nov 1st, 2006, 12:53 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You're missing a brace to close "if (ab == 1)" in main. This propagates, which kicks the error to a point following main. Let me emphasize that you appear to be missing a brace. It's very hard to tell with the weird alignment. See if your editor has matching-brace capabilities; it helps a lot.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 1st, 2006, 1:07 AM   #3
physicist
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 146
Rep Power: 3 physicist is on a distinguished road
dawei, omg you are a friggin genius!
IT COMPILES AND LINKS!!!!!!!!!!!!!!!!!!! OMGOMGOMG
AND
IT RUNS!
now i have to debug lol....some stuff works right but most of it doesnt
thats ok though that i can do myself (for now at least)
thanks so much DaWei, at that age you still have the keen eyes of a youngster
physicist is offline   Reply With Quote
Old Nov 1st, 2006, 1:10 AM   #4
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 894
Rep Power: 4 The Dark is on a distinguished road
You are missing a } after the call to initdisplay(); in the a==2 case.

The compiler is getting confused because it looks to it as if you are trying to define a function inside another function.

Edit: well that what I get for not refreshing.
The Dark is offline   Reply With Quote
Old Nov 2nd, 2006, 1:04 AM   #5
physicist
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 146
Rep Power: 3 physicist is on a distinguished road
i found a simpler way to make the program, takes up less than half the amount of code as well as 40% less file size BUT is just as effective and MOST IMPORTANTLY it works (whereas my other one doesnt LOL)
ill post it in the finished projects section
physicist is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
output - 842150451? programmingnoob C++ 3 Apr 23rd, 2006 9:23 PM
writing a scanner (lexical analysis) programmingnoob C++ 6 Mar 19th, 2006 5:12 PM
Pointers! Why? LOI Kratong C++ 33 Dec 18th, 2005 12:33 AM
BinaryTree , I need help on inserting expression to the Tree Master C# 3 Oct 14th, 2005 4:42 PM
Regular Expression HELP -- thanks paulchwd JavaScript and Client-Side Browser Scripting 3 Oct 11th, 2005 5:40 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC