Epected Primary Errors

This is a discussion on Epected Primary Errors within the C++ Programming forums, part of the General Programming Boards category; I am in a beginning programming class, and am having all these syntax errors that i can't fiugre out. Please ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    36

    Epected Primary Errors

    I am in a beginning programming class, and am having all these syntax errors that i can't fiugre out. Please help!

    Code:
    /#include <cstdio>                                                //Header Files
    #include <iostream>
    #include <cmath>
    #include <cstdlib>
    
    
    using namespace std;
    
    
    int main();
    int init_function();
    enum choice {regular=1, super, superdooper,quit};
    choice display_function();
    int big_switch();
    int calculate(int ,int); 
    int calculate(int);
    int superdooper_loop(int);
    int superdooper_calculate(int, char);
    void quit_pattern();
    void grand_total(int);
    static int rand_number;
    
    
    /************************************************************************************************
    MAIN
    purpose:
    input:
    returns:
    ************************************************************************************************/
    int main (){
        bool notValid;
        enum choice{regular=1, super=2, superdooper=3,quit=4};
        int age;
        display_function();
        do{                                                                //Validation for age
               notValid=false;
               printf ("\nHow old are you?");
               cin >> age;
                    if (age<1 || age>115)
                    {
                       cout << "Invalid entry.\n"; 
                       notValid=true;
                    }
        } while (notValid);
    int big_switch();
    }
    /************************************************************************************************
    INIT
    purpose:
    input:
    returns:
    ************************************************************************************************/
    int init_function(){
       int rand_number = rand(); 
       return(rand_number);
    }
    
    /************************************************************************************************
    DISPLAY
    purpose:                       displays menu
    input:                         choice
    returns:                       choice
    ************************************************************************************************/
    choice display_function (){
    enum choice {regular=1, super=2, superdooper=3,quit=4};
    cout << "Welcome to the Fair Price Car Wash\n\n";
    cout << "1)  Regular Car Wash\n"; 
    cout << "2)  Super Car Wash\n"; 
    cout << "3)  SuperDooper Car Wash\n"; 
    cout << "4)  Quit\n\n\n";
    cout << "Select one of the options:";
    cin >> choice;
    return(choice);
    }
    /************************************************************************************************
    BIG SWITCH
    purpose: 
    input: choice
    returns:
    ************************************************************************************************/
    int big_switch(choice){
    int passengers, age;
    bool notValid;
    switch (choice){
           case (regular):
           int calculate(int age, int number_pass); 
           break;
           case (super):
           int calculate(int age);
           break;
           case (superdooper):
                do{
                   notValid=false;                                            //Valioating for >4 passengers
                   cout << "\nHow many passengers do you have?";
                   cin >> passengers;
                         if (passengers >=4)
                            {
                            cout << "Invalid entry."; 
                            notValid=true;
                            }
                  }while (notValid);
    int superdooper_loop();
    break;
    case (quit):
    int quit_pattern();
    void grand_total();
    break;
    else
    cout << "Please enter a valid selection.";
    }
    /************************************************************************************************
    REG CALCULATE
    purpose: calculates price for regular
    input: number of passengers
    returns:
    ************************************************************************************************/
    int calculate(age, passengers){
     if (passengers>3)           
               {
               fee=passengers*age;
               grandtotal=grandtotal+fee;                             //Calculating price for #1
               printf ("%30s","The price for you is $");
               printf ("%-5.2lf", fee);
               cout << "\n\n";
               printf ("%30s","The grand total is $");
               printf ("%-5.2lf\n", grandtotal);
               }
         else 
               {      
               for(a=0;a<passengers;a++)                             //Display as many starts as the number of passengers
               cout << "*\n";
               grandtotal=grandtotal+fee;
               printf ("%30s","The price for you is $");
               printf ("%-5.2lf", fee);
               cout << "\n\n";
               printf ("%30s","The grand total is $");
               printf ("%-5.2lf""\n", grandtotal);
               }    
    void grand_total();
    cout << "The fee is: ", fee;
    }
    /************************************************************************************************
    SUPER CALCULATE
    purpose: calculate sproce for super
    input: 
    returns:
    ************************************************************************************************/
    int calculate(int){
        double  fee;
        int age;
        double grandtotal=grandtotal+fee;                                     //Calculating price for #2
         if  (age>=65)
               {
               fee=(age-65)*.5;
               printf ("%30s","The price for you is $");
               printf ("%-5.2lf", fee);
               cout << "\n\n";
               }
         else if(age% 2 == 0)
              cout << "\nNo Charge\n";
                   
         else
               {
               fee=age;
               grandtotal=grandtotal+fee;
               printf ("%30s","The price for you is $");
               printf ("%-5.2lf", fee);
               printf ("%30s","The grand total is $");
               printf ("%-5.2lf\n", grandtotal);
               cout << "\n\n";
               }
    void grand_total();
    cout << "The fee is: ", fee;
    }
    /************************************************************************************************
    SUPER DOOPER LOOP
    purpose: gets age, gender of passengers
    input: number of passengers
    returns: 
    ************************************************************************************************/
    int superdooper_loop(){
    int a, passage, passengers;
    char passgend;
        for (a=1;a<passengers;a++)                                      //Loop for passengers' ages and genders
               {
               cout << "\nEnter gender of passenger number ";
               cout << a, ":";
               cin >> passgend;
               cout << "\nEnter age of passenger number ";
               cout << a, ":";
               cin >> passage;
               }
    int superdooper_calculate(a, passage);       
    }
    /************************************************************************************************
    SUPER DOOPER CALCULATE
    purpose: calculates fee for option 3
    input: ages, genders
    returns:
    ************************************************************************************************/
    int superdooper_calculate(int passage, int age, char passgend){
    int passage, age;
    char f;
    double fee, grandtotal;
    char passgend;
    if (passgend=='f')                                           //Calculating for f passenger
                  {
                  fee=passage*1.5;
                  grandtotal=grandtotal+fee;
                  printf ("%30s","The price for you is $");
                  printf ("%-5.2lf", fee);
                  printf ("%30s","The grand total is $");
                  printf ("%-5.2lf\n", grandtotal);
                  cout << "\n\n";
                  }
               else                                                        //Calculating for f passenger
                  {
                  fee=2*age;
                  grandtotal=grandtotal+fee;
                  printf ("%30s","The price for you is $");
                  printf ("%-5.2lf", fee);
                  printf ("%30s","The grand total is $");
                  printf ("%-5.2lf\n", grandtotal);
                  cout << "\n\n";
                  }    
    void grand_total();
    cout << "The fee is: ", fee;  
        
    }    
    /************************************************************************************************
    QUIT PATTERN
    purpose: displays star pattern
    input: none
    returns: none
    ************************************************************************************************/
    int quit_pattern(){
    int row, space, asterisk;
        for(row=1; row<5; row++)
                  {
                  for(space=0; space>4+row; space++)
                     printf (" ");
                  for(asterisk=1; asterisk<=2*row; asterisk++)              //Displaying stars
                     printf("*");
                  cout << endl;
                  }
    }
    /************************************************************************************************
    GRAND TOTAL
    purpose: displays grand total
    input: random number
    returns:
    ************************************************************************************************/
    void grand_total(){
         static int rand_number;
         int fee;
          rand_number=init_function();
         double grandtotal=fee+rand_number;
         cout << "The grand total is :", grandtotal;
    }
    }
    Errors:
    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp" -o "C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.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\Compaq_Owner\Desktop\assignment 4 prototype.cpp: In function `choice display_function()':
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:77: error: expected primary-expression before ';' token
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:78: error: expected primary-expression before ')' token
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp: In function `int big_switch(choice)':
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:89: error: expected primary-expression before ')' token

    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:113: error: expected primary-expression before "else"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:113: error: expected `;' before "else"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:122: error: initializer expression list treated as compound expression
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:122: error: expected `,' or `;' before '{' token
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:153: error: expected primary-expression before "int"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:153: error: expected `;' before "int"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:186: error: expected primary-expression before "int"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:186: error: expected `;' before "int"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:206: error: a function-definition is not allowed here before '{' token
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:206: error: expected `,' or `;' before '{' token
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:241: error: expected primary-expression before "int"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:241: error: expected `;' before "int"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:258: error: expected primary-expression before "void"
    C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:258: error: expected `;' before "void"

    Execution terminated

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    This area is a little tweaked:
    Code:
    int big_switch(choice)
    {
       int passengers, age;
       bool notValid;
       switch ( choice )
       {
       case (regular):
          int calculate(int age, int number_pass); 
          break;
       case (super):
          int calculate(int age);
          break;
       case (superdooper):
          do
          {
             notValid=false;                                            //Valioating for >4 passengers
             cout << "\nHow many passengers do you have?";
             cin >> passengers;
             if ( passengers >=4 )
             {
                cout << "Invalid entry."; 
                notValid=true;
             }
          }while ( notValid );
          int superdooper_loop();
          break;
       case (quit):
          int quit_pattern();
          void grand_total();
          break;
       else
       cout << "Please enter a valid selection.";
       }
    [edit]And this is not the way to call a function:
    Code:
       int superdooper_calculate(a, passage);
    [edit=2]I'm less motiviated to continue when questions are forum-spammed.
    http://www.daniweb.com/forums/thread91145.html
    http://forums.devshed.com/c-programm...rs-478130.html
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    #include <stdio.h>
    
    int func (char v);
    
    int main()
    {
        char c='o';
        func(c); /*calls func() with parameter c, which is set to 'o', so it passes the character 'o' to func in func()'s 'char v'. */
    
        return 0;
    }
    
    int func(char v)
    {
        printf ("v is: &#37;c", v);
        return 0;
    }

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
        cin >> choice;
        return(choice);
    }
    choice is a type ( an enum ).
    You can't extract a type from a stream. redefining the enum doesn't help.
    try
    Code:
    choice display_function (){
    //enum choice {regular=1, super=2, superdooper=3,quit=4};
        int sel;
        cout << "Welcome to the Fair Price Car Wash\n\n";
        cout << "1)  Regular Car Wash\n"; 
        cout << "2)  Super Car Wash\n"; 
        cout << "3)  SuperDooper Car Wash\n"; 
        cout << "4)  Quit\n\n\n";
        cout << "Select one of the options:";
        cin >> sel;
        return  static_cast<choice>(sel);
    }
    Kurt

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    36
    Sorry, I didn't realize it was a bad thing to post in more than one forum. Just hoping to get an answer.

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    36
    Thanks, Kurt. That was a stupid mistake on my part!

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > Sorry, I didn't realize it was a bad thing to post in more than one forum
    Well it isn't, if you post on a forum and you get no response in a couple of days, then you're free to move on and try somewhere else.

    But concurrent posts on many forums is basically the same as writing "URGENT" in your attempt to hit as many people as possible.
    http://catb.org/~esr/faqs/smart-questions.html#urgent
    The downside is it really annoys helpers who frequent multiple forums.

    Also, consider http://catb.org/~esr/faqs/smart-questions.html#forum
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Sep 2007
    Posts
    36
    I'll keep that in mind. Thanks for the replies.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM

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