frustrated beginner

This is a discussion on frustrated beginner within the C++ Programming forums, part of the General Programming Boards category; hello everyone, I've been trying to debug my program and have fixed most of them... however, I'm once again at ...

  1. #1
    JCK
    JCK is offline
    Registered User
    Join Date
    Oct 2002
    Posts
    25

    frustrated beginner

    hello everyone,

    I've been trying to debug my program and have fixed most of them... however, I'm once again at the point that I'm staring at the codes... but feeling clueless........

    Could someone please help....
    Thanks so much

    here are the error code

    prog4.cc: In function `int main()':
    prog4.cc:57: parse error before `,'
    prog4.cc: In function `float CalculatePremium(int, char, basic_string<char,strin
    g_char_traits<char>,__default_alloc_template<false ,0> >)':
    prog4.cc:86: ANSI C++ forbids comparison between pointer and integer
    prog4.cc:182: ANSI C++ forbids comparison between pointer and integer


    and the following is the code....(sorry, it is long)

    staring line #14

    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <fstream>
    
    using namespace std;
    
    
    float CalculatePremium (int age, char gender, string type_coverage);    
                                    //function prototype
    
    int main()
    {
      string first_name;            //declare string variable first name
      string last_name;             //declare string variable last name
      string gender;                //declare string variable gender
      int age;                      //declare int variable age
      string type_coverage;         //declare string variable type of coverage
      string club_member;           //declare string variable health club
                                    //member
      string smoker;                //declare string variable smoker
      int zip_code;                 //declare int variable zip code
      int premium;                  //declare int variable premium
    
      ifstream inFile;              //declare file streams
      ofstream outFile;
      inFile.open("inputdata");     //opens the file
      if(!inFile)
      {
        cout << "Input file failed!" << endl;
        return 1;                   //terminates the program if input fails
      }    
    
    
      inFile >> first_name >> last_name >> gender >> age >> type_coverage >>
      club_member >> smoker >> zip_code;    //assigns input values from inFile
    
      cout << first_name << last_name << gender << age << type_coverage <<
      club_member << smoker << zip_code;    //echos the input on the monitor
    
      while (inFile)                        //looping in capturing &
                                            //processing input data
      {
        premium = CalculatePremium (int age, char gender, string
        type_coverage);
        outFile << first_name << last_name << type_coverage << zip_code
        << premium ;                        //output premium to file output
    
        inFile >> first_name >> last_name >> gender >> age >> type_coverage >>
        club_member >> smoker >> zip_code;  //assigns input values to inFile
    
        outFile.open("output");             //creates output data
      }
      outFile.open("output");
      if(!outFile)
      {
        cout << "Output file failed!" << endl;
        return 1;                   //terminates the program if output fials
      }
    }
    
    float CalculatePremium (int age, char gender, string type_coverage)
    {
    
      float basic_premium;          //declare float variable basic premium
      float discount_premium;       //declare float variable discount premium
      float premium;                //declare float variable adjusted premium
      string club_member;           //declare string variable health club
                                    //member
      string smoker;                //declare string variable smoker
      int zip_code;                 //declare int variable zip code
    
      if (gender == "male")
                                    //premium calcuation for male users
      {
        if (age < 25 )              //premium calculation for male under age
                                    //25
        {
          if (type_coverage == "single")
                                    //premium calculation for single
                                    //male under 25
          {
            basic_premium = 65.00;
          }
          else                      //premium calculation for male
                                    //under 25 with family
          {
            basic_premium = 175.00;
          }
        }
        else if (age >= 25 && age <35)
                                    //premium calculation for male 25-34
        {
          if (type_coverage == "single")
                                    //premium calculation for single male
                                    //25-34
          {
            basic_premium = 85.00;
          }
          else                      //premium claculation for male
                                    //25-34 w/ family
          {
            basic_premium = 215.00;
          }
        }
        else if (age >= 35 && age <45)
                                    //premium calculation for male 35-44
        {
          if (type_coverage == "single")
                                    //premium calculation for single male
                                    //35-44
          {
            basic_premium = 110.00;
          }
          else                      //premium calculation for male 35-44 w/
                                    //family
          {
            basic_premium = 325.00;
          }                     
        }
        else if (age >= 45 && age <55)
                                    //premium calculation for male 45-54
        {
          if (type_coverage == "single")
                                    //premium calculation for single male
                                    //45-54
          {
            basic_premium = 175.00;
          }
          else                      //premium calculation for male 45-54 w/
                                    //family
          {
            basic_premium = 450.00;
          }
        }
        else if (age >= 55 && age <65)
                                    //premium calculation for male 55-64
        {
        {
          if (type_coverage == "single")
                                    //premium calcualation for single male
                                    //55-64
          {
            basic_premium = 325.00;
          }
          else                      //premium calculation for male 55-64
                                    //w/family
          {
            basic_premium = 625.00;
          }
        }
        else                        //premium calculation for male 65 and
                                    //above
        {
    
          if (type_coverage == "single")
                                    //premium calculation for single male 65
                                    //and above
          {
            basic_premium = 450.00;
          }
          else                      //premium calculation for male >=65 w/
                                    //family
          {
            basic_premium = 850.00;
          }
        }
      }
    
      if (gender == "female")
                                    //premium calcuation for female users
      {
        if (age < 25 )              //premium calculation for female under age
                                    //25
        {
          if (type_coverage == "single")
                                    //premium calculation for single female
                                    //under 25
          {
            basic_premium = 60.00;
          }
          else                      //premium calculation for female under 25
                                    //w/ family
          {
            basic_premium = 165.00;
          }
        }
        else if (age >= 25 && age <35)
                                    //premium calculation for female 25-34
        {
          if (type_coverage == "single")
                                    //premium calculation for single female
                                    //25-34
          {
            basic_premium = 75.00;
          }
          else                      //premium claculation for female 25-34 w/
                                    //family
          {
            basic_premium = 210.00;
          }
        }
        else if (age >= 35 && age <45)
                                    //premium calculation for female 35-44
        {
          if (type_coverage == "single")
                                    //premium calculation for single female
                                    //35-44
          {
            basic_premium = 100.00;
          }
          else                      //premium calculation for female 35-44 w/
                                    //family
          {
            basic_premium = 310.00;
          }
        }
        else if (age >= 45 && age <55)
                                    //premium calculation for female 45-54
        {
          if (type_coverage == "single")
                                    //premium calculation for single female
                                    //45-54
          {
            basic_premium = 150.00;
          }
          else                      //premium calculation for female 45-54 w/
                                    //family
          {
            basic_premium = 425.00;
          }
        }
        else if (age >= 55 && age <65)
                                    //premium calculation for female 55-64
        {
          if (type_coverage == "single")
                                    //premium calcualation for single female
                                    //55-64
          {
            basic_premium = 310.00;
          }
          else                      //premium calculation for female 55-64
                                    //w/family
          {
            basic_premium = 595.00;
          }
        }
        else                        //premium calculation for female 65 and
                                    //above
        {
          if (type_coverage == "single")
                                    //premium calculation for single female 65
                                    //and above
          {
            basic_premium = 425.00;
          }
          else                      //premium calculation for female >=65 w/
                                    //family
          {
            basic_premium = 795.00;
          }
        }
      }
    
      if (smoker == "NonSmoker" && club_member == "Club")
      {
        discount_premium =  basic_premium * 0.9;
        //10% discount for non-smoker with health club membership
      }
      else if (smoker == "NonSmoker" && club_member == "NonClub")
      {
        discount_premium = basic_premium * 0.95;
        //5% discount for non-smoker without health club membership
      }
      else if (smoker == "Smoker" && club_member == "Club")
      {
        discount_premium = basic_premium * 0.95;
        //5% discount for smoker with health club membership
      }
      else
      {
        discount_premium = basic_premium;
        //no discount for smoker without health club membership
      }
    
    
      if (zip_code == 10000)
      {
        premium = discount_premium + 20;    //adjust premium by $20
      }
      else if (zip_code == 10001)
      {
        premium = discount_premium;         //premium stays the same
      }
      else if (zip_code == 10002)
      {
        premium = basic_premium +30;        //raise premium by $30
      }
      return premium;
    }

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You want to make gender a string, not a char.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    JCK
    JCK is offline
    Registered User
    Join Date
    Oct 2002
    Posts
    25
    duh......

    once again.... how did I miss all these things... I could not even understand what the error messages meant exactly....

    anyway, thanks so much.....

    one more question though,

    The parse error, is there a way that I can work around the "premium" assignment to make it fit in one line? is this the parse problem?



    Code:
    while (inFile)                        //looping in capturing &
                                            //processing input data
      {
        premium = CalculatePremium (int age, char gender, string
        type_coverage);
        outFile << first_name << last_name << type_coverage << zip_code
        << premium ;                        //output premium to file output

  4. #4
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Talking Wowser!

    premium = CalculatePremium (int age, char gender, string
    A problem you have here is that you function is calling 3 things in the parameters list but your input is more than 3. I think like 5/6 things. Thats one problem plus you have an extra '{' I found later down into your code and dont forget that your code has an extra else statement in it.

    I hope this helped some. good luck! i compiled 8 errors in this code alone.

    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  5. #5
    JCK
    JCK is offline
    Registered User
    Join Date
    Oct 2002
    Posts
    25
    correlcj,

    Thanks for the suggestions..... I fixed all the little bugs and realized that it might be easier just to write the whole program in straight forward codes instead of using functions for now since I'm not familiar enough about using functions yet, and I was getting even more error messages.

    Anyway, here are a couple more errors that I can't figure out, once again I have problem with the brace things....

    proj4.cc: In function `int main()':
    proj4.cc:276: parse error before `{'
    proj4.cc:287: confused by earlier errors, bailing out

    I'll post the code again since I've changed it...

    starting at line 12
    total number of lines about 296

    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
      string first_name;            //declare string variable first name
      string last_name;             //declare string variable last name
      string gender;                //declare string variable gender
      int age;                      //declare int variable age
      string type_coverage;         //declare string variable type of coverage
      string club_member;           //declare string variable health club
                                    //member
      string smoker;                //declare string variable smoker
      int zip_code;                 //declare int variable zip code
      float basic_premium;          //declare int variable basic premium
      float discount_premium;	//declare int variable discount premium
      float premium;		//declare int variable premium
    
    
      ifstream inFile;              //declare file streams
      ofstream outFile;
    
      inFile.open("inputdata");     //opens the file
      if(!inFile)
      {
        cout << "Input file failed!" << endl;
        return 1;                   //terminates the program if input fails
      }    
    
    
      inFile >> first_name >> last_name >> gender >> age >> type_coverage >>
      club_member >> smoker >> zip_code;    //assigns input values from inFile
    
      cout << first_name << last_name << gender << age << type_coverage <<
      club_member << smoker << zip_code;    //echos the input on the monitor
    
      while (inFile)                        //looping in capturing &
                                            //processing input data
      {
        if (gender == "male")
                                    //premium calcuation for male users
        {
          if (age < 25 )            //premium calculation for male under age
                                    //25
          {
            if (type_coverage == "single")
                                    //premium calculation for single
                                    //male under 25
            {
              basic_premium = 65.00;
            }
            else                    //premium calculation for male
                                    //under 25 with family
            {
              basic_premium = 175.00;
            }
          }
          else if (age >= 25 && age <35)
                                    //premium calculation for male 25-34
          {
            if (type_coverage == "single")
                                    //premium calculation for single male
                                    //25-34
            {
              basic_premium = 85.00;
            }
            else                    //premium claculation for male
                                    //25-34 w/ family
            {
              basic_premium = 215.00;
            }
          }
          else if (age >= 35 && age <45)
                                    //premium calculation for male 35-44
          {
            if (type_coverage == "single")
                                    //premium calculation for single male
                                    //35-44
            {
              basic_premium = 110.00;
            }
            else                    //premium calculation for male 35-44 w/
                                    //family
            {
              basic_premium = 325.00;
            }                     
          }
          else if (age >= 45 && age <55)
                                    //premium calculation for male 45-54
          {
            if (type_coverage == "single")
                                    //premium calculation for single male
                                    //45-54
            {
              basic_premium = 175.00;
            }
            else                    //premium calculation for male 45-54 w/
                                    //family
            {
              basic_premium = 450.00;
            }
          }
          else if (age >= 55 && age <65)
                                    //premium calculation for male 55-64
          {
            if (type_coverage == "single")
                                    //premium calcualation for single male
                                    //55-64
            {
              basic_premium = 325.00;
            }
            else                    //premium calculation for male 55-64
                                    //w/family
            {
              basic_premium = 625.00;
            }
          }
          else                      //premium calculation for male 65 and
                                    //above
          {
            if (type_coverage == "single")
                                    //premium calculation for single male 65
                                    //and above
            {
              basic_premium = 450.00;
            }
            else                    //premium calculation for male >=65 w/
                                    //family
            {
              basic_premium = 850.00;
            }
          }
        }
    
        if (gender == "female")
                                    //premium calcuation for female users
        {
          if (age < 25 )            //premium calculation for female under age
                                    //25
          {
            if (type_coverage == "single")
                                    //premium calculation for single female
                                    //under 25
            {
              basic_premium = 60.00;
            }
            else                    //premium calculation for female under 25
                                    //w/ family
            {
              basic_premium = 165.00;
            }
          }
          else if (age >= 25 && age <35)
                                    //premium calculation for female 25-34
          {
            if (type_coverage == "single")
                                    //premium calculation for single female
                                    //25-34
            {
              basic_premium = 75.00;
            }  
            else                    //premium claculation for female 25-34 w/
                                    //family
            {
              basic_premium = 210.00;
            }
          }
          else if (age >= 35 && age <45)
                                    //premium calculation for female 35-44
          {
            if (type_coverage == "single")
                                    //premium calculation for single female
                                    //35-44
            {
              basic_premium = 100.00;
            }
            else                    //premium calculation for female 35-44 w/
                                    //family
            {
              basic_premium = 310.00;
            }
          }
          else if (age >= 45 && age <55)
                                    //premium calculation for female 45-54
          {
            if (type_coverage == "single")
                                    //premium calculation for single female
                                    //45-54
            {
              basic_premium = 150.00;
            }
            else                    //premium calculation for female 45-54 w/
                                    //family
            {
              basic_premium = 425.00;
            }
          }
          else if (age >= 55 && age <65)
                                    //premium calculation for female 55-64
          {
            if (type_coverage == "single")
                                    //premium calcualation for single female
                                    //55-64
            {
              basic_premium = 310.00;
            }
            else                    //premium calculation for female 55-64
                                    //w/family
            {
              basic_premium = 595.00;
            }
          }
          else                      //premium calculation for female 65 and
                                    //above
          {
            if (type_coverage == "single")
                                    //premium calculation for single female 65
                                    //and above
            {
              basic_premium = 425.00;
            }
            else                    //premium calculation for female >=65 w/
                                    //family
            {
              basic_premium = 795.00;
            }
          }
        }
    
        if (smoker == "NonSmoker" && club_member == "Club")
        {
          discount_premium =  basic_premium * 0.9;
          //10% discount for non-smoker with health club membership
        }
        else if (smoker == "NonSmoker" && club_member == "NonClub")
        {
          discount_premium = basic_premium * 0.95;
          //5% discount for non-smoker without health club membership
        }
        else if (smoker == "Smoker" && club_member == "Club")
        {
          discount_premium = basic_premium * 0.95;
          //5% discount for smoker with health club membership
        }
        else
        {
          discount_premium = basic_premium;
          //no discount for smoker without health club membership
        }
    
        if (zip_code == 10000)
        {
          premium = discount_premium + 20;    //adjust premium by $20
        }
        else if (zip_code == 10001)
        {
          premium = discount_premium;         //premium stays the same
        }
        else (zip_code == 10002)
        {
          premium = basic_premium +30;        //raise premium by $30
        }
      
        outFile << first_name << last_name << type_coverage << zip_code
        << premium ;                        //output premium to file output
    
        inFile >> first_name >> last_name >> gender >> age >> type_coverage >>
        club_member >> smoker >> zip_code;  //assigns input values to inFile
    
        outFile.open("output");             //creates output data
      }
      outFile.open("output");
      if(!outFile)
      {
        cout << "Output file failed!" << endl;
        return 1;                   //terminates the program if output fials
      }
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. Another frustrated beginner...
    By mfskratch in forum C Programming
    Replies: 11
    Last Post: 09-25-2007, 08:10 AM
  3. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 10:21 AM
  4. so confused and frustrated
    By ct26torr in forum C Programming
    Replies: 2
    Last Post: 02-13-2003, 09:40 PM

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