New Posts  All Forums:Forum Nav:

another C+++ question

post #1 of 7
Thread Starter 
another C++ question
when i compile this program
Code:
/////////////////////////////


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

#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 <<"\
";
          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 <<"\
enter P1 original rating (see above):";
               cin >>pa;
               cout <<"\
enter 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 << "////////////////////////////////////\
";
         cout << "Chess Rating Manager v1.0\
";
         cout << "Sreenath Pillai\
";
         cout << "////////////////////////////////////\
\
\
\
";
         cout << "[1] Add Player\
";
         cout << "[2] Score Game\
";
         cout << "[3] Check Ratings\
";   
         cout << "[4] Quit\
";
         cout << "\
\
Choose:";
    }   
    void secdisplay()
    {
         cout << "\
\
[1] both players rated OR both players provisional\
";
         cout << "[2] one player rated and one player provisional\
"; 
         cout << "[3] Back";
         cout << "\
\
Choose:";
    }              
    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\
ew.cpp expected primary-expression before "void"
117 C:\\Dev-Cpp\
ew.cpp expected `;' before "void"
129 C:\\Dev-Cpp\
ew.cpp expected primary-expression before "void"
129 C:\\Dev-Cpp\
ew.cpp expected `;' before "void"
137 C:\\Dev-Cpp\
ew.cpp a function-definition is not allowed here before '{' token
137 C:\\Dev-Cpp\
ew.cpp expected `,' or `;' before '{' token
141 C:\\Dev-Cpp\
ew.cpp a function-definition is not allowed here before '{' token
141 C:\\Dev-Cpp\
ew.cpp expected `,' or `;' before '{' token
145 C:\\Dev-Cpp\
ew.cpp a function-definition is not allowed here before '{' token
145 C:\\Dev-Cpp\
ew.cpp expected `,' or `;' before '{' token
147 C:\\Dev-Cpp\
ew.cpp expected `}' at end of input
so really everything is right except there are really only 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 fellow coders!!!
    
CPUMotherboardGraphicsRAM
Intel C2D e6400 GIGABYTE GA965P-S3 nVidia GeForce 7600GT 1 GB DDR 800 OCZ Gold 
Hard DriveOptical DriveOSMonitor
160GB WD DVD+-RW XP-games+Gentoo-programmin 21' Sun CRT (pwns LCD) 
KeyboardPowerCaseMouse
Regular PS/2 &quot;Quietkey&quot; 680WEchoStar+500Wforfans Uber-modded SuperTower(got for $16!)dual PSU+LEDs USB Optical Dell *ewww, dell* 
Mouse Pad
"ALGOR" POS 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel C2D e6400 GIGABYTE GA965P-S3 nVidia GeForce 7600GT 1 GB DDR 800 OCZ Gold 
Hard DriveOptical DriveOSMonitor
160GB WD DVD+-RW XP-games+Gentoo-programmin 21' Sun CRT (pwns LCD) 
KeyboardPowerCaseMouse
Regular PS/2 &quot;Quietkey&quot; 680WEchoStar+500Wforfans Uber-modded SuperTower(got for $16!)dual PSU+LEDs USB Optical Dell *ewww, dell* 
Mouse Pad
"ALGOR" POS 
  hide details  
Reply
post #2 of 7
I don't have a C++ compiler on this machine so I can't tell you exactly what the issue is. It looks like it's trying to include your function declaration in the other part of the code because it's expecting a primary expression somewhere. Generally, that means you haven't finished off some other expression in your main function. The solution? I would go over the code with a fine tooth comb and make sure you've terminated all your statements with ; and that all program segments are properly braced ie { }.

If you haven't properly terminated an earlier code segment, the compiler will just assume that your function declaration at line 117 is still part of your main function. That's my best guess anyway.
RAID0R
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 750 4.0GHz MSI P55-GD80 GTX 470 | 8800GT PhysX 2x2GB G.Skill Ripjaws 
Hard DriveOptical DriveCoolingOS
60GB Agility 2|1TB RAID0|1.5TB Pioneer DVR-217D XSPC Raystorm | XSPC RX240 Windows 7 Professional x64 
MonitorKeyboardPowerCase
27" Dell 2709W | 17" Samsung Logitech G15 Corsair HX850 Corsair 650D 
Mouse
Microsoft IntelliMouse 
  hide details  
Reply
RAID0R
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 750 4.0GHz MSI P55-GD80 GTX 470 | 8800GT PhysX 2x2GB G.Skill Ripjaws 
Hard DriveOptical DriveCoolingOS
60GB Agility 2|1TB RAID0|1.5TB Pioneer DVR-217D XSPC Raystorm | XSPC RX240 Windows 7 Professional x64 
MonitorKeyboardPowerCase
27" Dell 2709W | 17" Samsung Logitech G15 Corsair HX850 Corsair 650D 
Mouse
Microsoft IntelliMouse 
  hide details  
Reply
post #3 of 7
i think i will agree

if your interested
Quote:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp" -o "C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.exe" -I"C:\\Dev-Cpp\\lib\\gcc\\mingw32\\3.4.2\\include" -I"C:\\Dev-Cpp\\include\\c++\\3.4.2\\backward" -I"C:\\Dev-Cpp\\include\\c++\\3.4.2\\mingw32" -I"C:\\Dev-Cpp\\include\\c++\\3.4.2" -I"C:\\Dev-Cpp\\include" -L"C:\\Dev-Cpp\\lib"
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp: In function `int main()':
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:117: error: expected primary-expression before "void"
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:117: error: expected `;' before "void"
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:129: error: expected primary-expression before "void"
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:129: error: expected `;' before "void"

C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:137: error: a function-definition is not allowed here before '{' token

C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:137: error: expected `,' or `;' before '{' token
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:141: error: a function-definition is not allowed here before '{' token
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:141: error: expected `,' or `;' before '{' token
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:145: error: a function-definition is not allowed here before '{' token
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:145: error: expected `,' or `;' before '{' token
C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp:147: error: expected `}' at end of input

Execution terminated

edit: i managed to get it down to 2 errors. but theyre in line 146:

Quote:
146 C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp expected `)' before ';' token
146 C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp [Warning] converting to `int' from `double'
edit again: down to one error

Quote:
146 C:\\Documents and Settings\\sleeper\\Desktop\\Untitled1.cpp [Warning] converting to `int' from `double'
edit for a third time:

i got it to compile. it still gives me 1 error but it compiles and it runs.

Code:
/////////////////////////////


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

#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 <<"\
";
          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 <<"\
enter P1 original rating (see above):";
               cin >>pa;
               cout <<"\
enter 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 << "////////////////////////////////////\
";
         cout << "Chess Rating Manager v1.0\
";
         cout << "Sreenath Pillai\
";
         cout << "////////////////////////////////////\
\
\
\
";
         cout << "[1] Add Player\
";
         cout << "[2] Score Game\
";
         cout << "[3] Check Ratings\
";   
         cout << "[4] Quit\
";
         cout << "\
\
Choose:";
    }   
    void secdisplay()
    {
         cout << "\
\
[1] both players rated OR both players provisional\
";
         cout << "[2] one player rated and one player provisional\
"; 
         cout << "[3] Back";
         cout << "\
\
Choose:";
    }              
    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);
        }
what i removed is in red and what i added is in green
dont forget to remove the color tags if you copy it. that would prbly destroy your code and give you errors.
<3
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II 955 BE MSI 790FX-GD70 HIS HD4890 4GB G.Skill DDR3 PC3-16000 2000MHz Ripjaw CL 9's 
Hard DriveOptical DriveOSMonitor
wd caviar black 750gig samsung Win7 Asus 25.5 1920x1200 
KeyboardPowerCaseMouse
Logitec G15 Corsair TX750W lian-li pc1000b plus II Razer Copperhead Green 
Mouse Pad
Steel Series 5L 
  hide details  
Reply
<3
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II 955 BE MSI 790FX-GD70 HIS HD4890 4GB G.Skill DDR3 PC3-16000 2000MHz Ripjaw CL 9's 
Hard DriveOptical DriveOSMonitor
wd caviar black 750gig samsung Win7 Asus 25.5 1920x1200 
KeyboardPowerCaseMouse
Logitec G15 Corsair TX750W lian-li pc1000b plus II Razer Copperhead Green 
Mouse Pad
Steel Series 5L 
  hide details  
Reply
post #4 of 7
Thread Starter 
thanks. LOL i got it myself the EXACT SAME way you did sleeper, found the two missing (one { and one ) )
got it to run
nothing works right though
if you can sleeper try running press 1 to add player and you will see it doesnt work. also try to score player, still doesnt work
    
CPUMotherboardGraphicsRAM
Intel C2D e6400 GIGABYTE GA965P-S3 nVidia GeForce 7600GT 1 GB DDR 800 OCZ Gold 
Hard DriveOptical DriveOSMonitor
160GB WD DVD+-RW XP-games+Gentoo-programmin 21' Sun CRT (pwns LCD) 
KeyboardPowerCaseMouse
Regular PS/2 &quot;Quietkey&quot; 680WEchoStar+500Wforfans Uber-modded SuperTower(got for $16!)dual PSU+LEDs USB Optical Dell *ewww, dell* 
Mouse Pad
"ALGOR" POS 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel C2D e6400 GIGABYTE GA965P-S3 nVidia GeForce 7600GT 1 GB DDR 800 OCZ Gold 
Hard DriveOptical DriveOSMonitor
160GB WD DVD+-RW XP-games+Gentoo-programmin 21' Sun CRT (pwns LCD) 
KeyboardPowerCaseMouse
Regular PS/2 &quot;Quietkey&quot; 680WEchoStar+500Wforfans Uber-modded SuperTower(got for $16!)dual PSU+LEDs USB Optical Dell *ewww, dell* 
Mouse Pad
"ALGOR" POS 
  hide details  
Reply
post #5 of 7
i think you need to have the input for player 1 and then the input for player 2 after you enter player 1 and press enter. ill look into coding that little section so that it works tonight.
<3
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II 955 BE MSI 790FX-GD70 HIS HD4890 4GB G.Skill DDR3 PC3-16000 2000MHz Ripjaw CL 9's 
Hard DriveOptical DriveOSMonitor
wd caviar black 750gig samsung Win7 Asus 25.5 1920x1200 
KeyboardPowerCaseMouse
Logitec G15 Corsair TX750W lian-li pc1000b plus II Razer Copperhead Green 
Mouse Pad
Steel Series 5L 
  hide details  
Reply
<3
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II 955 BE MSI 790FX-GD70 HIS HD4890 4GB G.Skill DDR3 PC3-16000 2000MHz Ripjaw CL 9's 
Hard DriveOptical DriveOSMonitor
wd caviar black 750gig samsung Win7 Asus 25.5 1920x1200 
KeyboardPowerCaseMouse
Logitec G15 Corsair TX750W lian-li pc1000b plus II Razer Copperhead Green 
Mouse Pad
Steel Series 5L 
  hide details  
Reply
post #6 of 7
Thread Starter 
i found an easier way to make the program
it works perfectly and is compact
it can be found at
www.sreenathpillai.frih.net/simplechessprog.rar
edit:added as attachment as well
    
CPUMotherboardGraphicsRAM
Intel C2D e6400 GIGABYTE GA965P-S3 nVidia GeForce 7600GT 1 GB DDR 800 OCZ Gold 
Hard DriveOptical DriveOSMonitor
160GB WD DVD+-RW XP-games+Gentoo-programmin 21' Sun CRT (pwns LCD) 
KeyboardPowerCaseMouse
Regular PS/2 &quot;Quietkey&quot; 680WEchoStar+500Wforfans Uber-modded SuperTower(got for $16!)dual PSU+LEDs USB Optical Dell *ewww, dell* 
Mouse Pad
"ALGOR" POS 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel C2D e6400 GIGABYTE GA965P-S3 nVidia GeForce 7600GT 1 GB DDR 800 OCZ Gold 
Hard DriveOptical DriveOSMonitor
160GB WD DVD+-RW XP-games+Gentoo-programmin 21' Sun CRT (pwns LCD) 
KeyboardPowerCaseMouse
Regular PS/2 &quot;Quietkey&quot; 680WEchoStar+500Wforfans Uber-modded SuperTower(got for $16!)dual PSU+LEDs USB Optical Dell *ewww, dell* 
Mouse Pad
"ALGOR" POS 
  hide details  
Reply
post #7 of 7
thats what i was trying to get at with cin >> but it was being glitchy and i was getting pissed.
<3
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II 955 BE MSI 790FX-GD70 HIS HD4890 4GB G.Skill DDR3 PC3-16000 2000MHz Ripjaw CL 9's 
Hard DriveOptical DriveOSMonitor
wd caviar black 750gig samsung Win7 Asus 25.5 1920x1200 
KeyboardPowerCaseMouse
Logitec G15 Corsair TX750W lian-li pc1000b plus II Razer Copperhead Green 
Mouse Pad
Steel Series 5L 
  hide details  
Reply
<3
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II 955 BE MSI 790FX-GD70 HIS HD4890 4GB G.Skill DDR3 PC3-16000 2000MHz Ripjaw CL 9's 
Hard DriveOptical DriveOSMonitor
wd caviar black 750gig samsung Win7 Asus 25.5 1920x1200 
KeyboardPowerCaseMouse
Logitec G15 Corsair TX750W lian-li pc1000b plus II Razer Copperhead Green 
Mouse Pad
Steel Series 5L 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming