Thread: hhhh.....elp!

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    25

    hhhh.....elp!

    Hi everyone,

    I'm still working on the same project and my brain just doesn't work any more......

    I tried to use functions and it gave me more problems, so I went back and made it a straight main function program.... but I'm still getting those da*e error messages that I have no clue of....

    can any one shed some light??
    Thanks so much, I so so appreciate everyone's help....

    here are the error messages

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


    here is the program, sorry it is a bit long.....

    starting at line12

    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("proj4.in");     //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 = discount_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("proj4.out");             //creates output data
      }
      outFile.open("proj4.out");
      if(!outFile)
      {
        cout << "Output file failed!" << endl;
        return 1;                   //terminates the program if output fials
      }
      return 0;
    }

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
        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 = discount_premium +30;        //raise premium by $30
        }

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    25

    using "Tab" in output/print out

    Salem and Monster,

    Thank you both very much..... I looked over my codes more carefully and found those mistakes that you two have caught....
    I was finally able to compile my program and run it. The only last thing is that I would like to line up the output, does anyone know what syntax I can use to put a "tab" between each print out?


    Thanks so much!

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Code:
    cout << "\t";
    displays a tab.

    If you want to line up your output you can use setw() which is in the iomanip library.

Popular pages Recent additions subscribe to a feed