expected primary expansion before ')' token.

This is a discussion on expected primary expansion before ')' token. within the C++ Programming forums, part of the General Programming Boards category; Ok i cant figure out whats wrong with my code, im just making this for a little practice. Im only ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    6

    expected primary expansion before ')' token.

    Ok i cant figure out whats wrong with my code, im just making this for a little practice. Im only 14 and ive been doing c++ for ummm 2 days now i think it is. The problem is always get stuck with a weird error, it varies from the different lil aps i write, usually it says that a { isnt there when it is so i have to delete it, try to compile, then reinsert it, compile and then it will run even though its the same as before. Unfortunatly this isnt working with this problem. Heres my code *no where near completed*

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int X;
        
        cout<<"This program is designed to work as a times table.  Please enter a number from 1-9 and all of the expressions up to *9 will be displayed for that number.\n";
        cout<<endl;
        cout<<"Please enter the number you would like the times table for.: ";
        cin>> X;
        cin.ignore();
        
        if ( X == 1) {
             for  ( X = 1; X < 9; X** ) {
                 cout<< X <<endl;
                 }
                 }
    cin.get();
    }
    i get the error

    expected primary expansion before ')' token.

    for this line

    for ( X = 1; X < 9; X** ) {

    the thing is there IS a primary expansion token on the line RIGHT ABOvE IT!

    if ( X == 1) { <---- there it is lol.

    so idk wth is wrong with it, maybe i dont have my {} in the right places or something. any help would be nice since i kind of want this to work because it would be good extra credit for my computerclass.


    O and also will the X** times X by 2,3,4,5, etc.? or is that screwed up as well?
    Last edited by agent d00nut; 11-05-2005 at 07:49 PM.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    No X** doesn't make any sense and doesn't do anything. If you're attempting to relate it to X++, then you would have to assume it would do X*1... which really doesn't do much of anything does it. Your problem is in the X**, as it's not proper syntax and their for not a primary expression.

    You have a few logical errors in this program as well, I can tell you right now, that even if you somehow fixed the syntax error without changing the integrity of what the program does, then it wouldn't do your times table.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    6
    =( well ** SEEMED like a good idea but i guess it doesnt make much sense now that i think about it, even if it was the right syntex 1*1 = 1 which would create an infinate loop i think. =/

    K, note to self. Learn more then 2 days of C++ and try again later.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    If I may, with your permission. I'll quickly fix this program for you and show you how it works.
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    6
    Well i think i found a way to get it to work, i still have that infinite loop problem though lol.
    Code:
        if ( X == 1 ) {
             for  ( X = 1; X < 9; X * 1 ) {
                 cout<< X <<endl;
    thats how that new block of code works but i sitll have the problem of incressing the one each time, if you show me how to do that i may be able to figure out the rest.

    Also thanks for the offer of showing me how to do it but i would like to try and get this to work with as little help as possible. Although if i cant figure it out, ill give you permission to change and fix it so i can learn what i did wrong.

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Let me explain a bit about for loops.

    The declaration of a for loop is like this
    [CODE] for (variable initialization; condition to loop; update on loop)[CODE]

    Now considering that, look at what your loop would do after a few times of looping:

    Code:
        if ( X == 1 ) {
             for  ( X = 1; X < 9; X * 1 ) {
                 cout<< X <<endl;
             }
    
    /* When it enters, X = 1. It outputs the value of X(1). It gets to the end of the 
    loop and checks the condition to stay in. X(1) is less then 9 so it loops again.
    It makes the update X(1) * 1 = 1... Notice that it puts it nowhere, so this does nothing
    It loops again... It outputs the value of X(1). It gets to the end of the 
    loop and checks the condition to stay in. X(1) is less then 9 so it loops again. 
    
    It does this forever cause your update gets you no closer to your condition
    for exiting the loop*/
    I'd read more about for loops, because you seem to be uncertain on how they work.
    Sent from my iPadŽ

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    6
    No i understood why it created the infinite loop thing. I then realized i forgot to put

    X++; at the end of the loop, so X never increased which = infinite loop.

    Ok so now that i know how to set up my loops i just ran the program, entered one, and then i realized it just gives me, 1-9. I want it to say

    1*1=1
    1*2=2

    etc.

    Any ideas on how i would accomplish that?

  8. #8
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    you have to program it to display whatever text you want. Here's an example
    Code:
      
             for  ( X = 1; X < 9; X++) {
                 cout<< "1 * " << X << " = " << X <<endl;
             }

  9. #9
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Also, you should ask yourself if you could do that with one variable. You have your initial number, and then you have your product of the multiplication.
    Sent from my iPadŽ

  10. #10
    Registered User
    Join Date
    Nov 2005
    Posts
    6
    SUCCESS!

    Lol thanks for your help both of you =). Now i just gotta write the rest of the program. Heres the code so far.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int X;
        int Z;
        int Y;
        
        cout<<"This program is designed to work as a times table.  Please enter a number from   1-9 and all of the expressions up to *9 will be displayed for that number.\n";
        cout<<endl;
        cout<<"Please enter the number you would like a times table for: ";
        cin>> X;
        cin.ignore();
        
        if ( X == 1 ) {
             for  ( X = 1, Y = 1, Z = 1; Y < 10; X * Y ) {
                 cout<<X << "*" <<Y <<"="<< Z <<endl;
                 Z++;
                 Y++;
                 }
                 }
    cin.get();
    }
    It obviously only works for 1 right now but still i should be able to finish in like 30 or 40 minutes.

    *******

    Actually i lied that didnt work. THIS worked

    Code:
        if ( X == 2 ) {
             for  ( X, Y = 2, Z = 1; Z < 10; X = Y * Z ) {
                  cout<<Y << "*" <<Z <<"="<< X <<endl;
                  Z++;
                  }
    Alright now everything seems to be working fine =) thanks again guys.

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    6
    Ok one last question.

    How can i get my program to only shut if you push the X, or like you type quit at any time and it would close down? Because right now it just gives you the * table for what you want then closes after you push enter.

    Im thinking i would need some kind of loop that kept the program from closing but i have no idea how to go about doing that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 09:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21