Thread: Please Help.......

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

    Unhappy Please Help.......

    Hi everyone,

    I just started taking C++ class, and I'm stuck on this one project. I finished the code and tried to compile it and got the following message:

    nova> g++ -o proj3 proj3.cc
    proj3.cc:245: unterminated string or character constant
    proj3.cc:33: possible real start of unterminated constant

    Could anyone help?? I looked all over the place and still could not figure out.......

    Thanks so so much!!

    Here is the program:



    Code:
    #include<iostream>
    
    Using namespace std;
    
    int main()
    {
      string full_name;             //declare string variable full name
      string gender;                //declare string variable gender
      int age;                      //declare int variable age
      string type_coverage;         //declare string variable type of coverage
      int zip_code;                 //declare int variable zip code
      float basic_premium;          //declare float variable basic premium
      float adjusted_premium;       //declare float variable adjusted premium
                                    //based on the user's zip code  
    
      cout<<"Please enter your full name (First Last)";
                                    //promt the user to enter his or her name
      cint>> full_name;             //read user name
      cout<< "Please enter your gender:";
                                    //promt the user to enter gender
      cint>> gender;                //read user gender
      cout<< "Please enter your age:";
                                    // promt the user to enger age
      cint>> age;                   //read user age
      cout<< "Please enter your type of type of coverage, 'Single' or
      'Family';
                                    //promt the user to enter type of coverage
      cint>> type_coverage;         //read type of coverage
      cout<< "Please enter your zip code:";
                                    //promt the user to enter zip code
      cint>> 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 == 'Sigle')     //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;
          }
        }
        cout << "full_name premium of type_coverage coverage is basic_premium"
        << endl;        
      }
    
       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;
          }
        }
         cout << "full_name premium of type_coverage coverage is basic_premium"
        << endl;
      }
    
      if (zip_code == '1000')
      {
        adjusted_premium = basic_premium * 1.1      //raise discounted premium
                                                    //by 10%
        cout << "Monthly premium for full_name of Zip Code zip_code with
        type_coverage coverage is adjusted_premium" << endl;
    					//output the ajusted premium on
                                            //the monitor
      }
      else if (zip_code == '1001')
      {
        adjusted_premium = basic_premium    //premium stays the same
        cout << "Monthly premium for full_name of Zip Code zip_code with
        type_coverage coverage is adjusted_premium" << endl;
                                            //output the ajusted premium on
                                            //the monitor
      }      
      else if (zip_code == '1002')
      {
        cout << "Monthly premium for full_name of Zip Code zip_code with
        type_coverage coverage is adjusted_premium" << endl;
                                            //output the ajusted premium on
                                            //the monitor
    
      }
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    These are all simple syntax errors, and none of them were cryptic if you try to figure them out. Here is the fixed code, it's long, so don't expect me to do it again, and it only compiles, I didn't run it:
    Code:
    //Jueichuan Connie Kang
    //Project 3
    //Source File: proj3.cc
    //CMIS 140 4021
    //User ID: cm140b15
    //University of Maryland
    //Fall, 2002
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
      string full_name;             //declare string variable full name
      string gender;                //declare string variable gender
      int age;                      //declare int variable age
      string type_coverage;         //declare string variable type of coverage
      int zip_code;                 //declare int variable zip code
      float basic_premium;          //declare float variable basic premium
      float adjusted_premium;       //declare float variable adjusted premium
      //based on the user's zip code  
      
      cout<<"Please enter your full name (First Last)";
      //promt the user to enter his or her name
      cin>> full_name;             //read user name
      cout<< "Please enter your gender:";
      //promt the user to enter gender
      cin>> gender;                //read user gender
      cout<< "Please enter your age:";
      // promt the user to enger age
      cin>> age;                   //read user age
      cout<< "Please enter your type of type of coverage, 'Single' or 'Family'";
      //promt the user to enter type of coverage
      cin>> type_coverage;         //read type of coverage
      cout<< "Please enter your zip code:";
      //promt the user to enter zip code
      cin>> 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;
        }
      }
      cout << "full_name premium of type_coverage coverage is basic_premium"
        << endl;        
      
      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;
          }
        }
        cout << "full_name premium of type_coverage coverage is basic_premium"
          << endl;
      }
      
      if (zip_code == 1000)
      {
        adjusted_premium = basic_premium * 1.1;      //raise discounted premium
        //by 10%
        cout << "Monthly premium for full_name of Zip Code zip_code with"
          "type_coverage coverage is adjusted_premium" << endl;
        //output the ajusted premium on
        //the monitor
      }
      else if (zip_code == 1001)
      {
        adjusted_premium = basic_premium;    //premium stays the same
        cout << "Monthly premium for full_name of Zip Code zip_code with"
          "type_coverage coverage is adjusted_premium" << endl;
        //output the ajusted premium on
        //the monitor
      }      
      else if (zip_code == 1002)
      {
        cout << "Monthly premium for full_name of Zip Code zip_code with"
          "type_coverage coverage is adjusted_premium" << endl;
        //output the ajusted premium on
        //the monitor
        
      }
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    6
    cout<< "Please enter your type of type of coverage, 'Single' or
    'Family';


    You should have another " at the end of the line before the semicolon and / infront of the single quotes to output them instead of interperate them like:

    cout<< "Please enter your type of type of coverage, /'Single/' or /'Family/'";

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

    Wink

    Hi soaponarope and prelude,

    Thanks so much for the help.
    I didn't expect anyone to rewrite my code, just a couple of pointers as what the problems are so I understand what I did wrong. I guess for me it is hard to figure out the syntax errors after staring the codes for hours....

    Just a couple more of questions, what is wrong with line 33, I'm not sure what the message meant by "unterminated constant"?

    Thanks so much again

    proj3.cc:245: unterminated string or character constant
    proj3.cc:33: possible real start of unterminated constant

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Ouch Prelude has caught elseifheimers disease!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

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

    Smile

    Thanks so much Salem, I understand it now....

    I'm at the debugging stage, and here is another puzzle that I can't figure out....

    here are the partical code, it runs but for some reasons, the program takes the full name and print out "please enter your gender" and immediately jumps to printing "please enter your age" without taking any input from the user. But afterward, it works on taking the coverage and the zip code correctly......

    could anybody provide some insight?
    Thanks so much again!!


    Code:
     cout <<"Please enter your full name (First Last)";
                                    //promt the user to enter his or her name
      cin >> full_name;             //read user name
      cout << "Please enter your gender:" ;
                                    //promt the user to enter gender
      cin >> gender;                //read user gender
      cout << "Please enter your age:";
                                    // promt the user to enger age
      cin >> age;                   //read user age
      cout << "Please enter your type of type of coverage, Single or Family:";
                                    //promt the user to enter type of coverage
      cin >> type_coverage;         //read type of coverage
      cout << "Please enter your zip code:";
                                    //promt the user to enter zip code
      cin>> zip_code;               //read zip code

  7. #7
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    I don't know this for certain (I'm away from my compiler), but I'm pretty sure that cin only reads in characters up to the first whitespace it encounters. I'll bet that if you cout your full_name and gender, you'll find that the first name is in full_name and the last name is in gender.

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    25
    Hi pianorain,

    Thanks so much for the input..... I think you are right, I remeber now that C++ reads only up to the white space. I have worked on it to make all the ajustment and here comes more problems..... I guess programming isn't as easy as I thought....

    I got couple more error messages that I couldn't figure out.... I had similar problems before and I figured out it was a missing brace, but this one, I'm stuck again.....

    here is the partial code starting line 77

    prog3.cc: In function `int main()':
    prog3.cc:86: parse error before `}'
    prog3.cc:89: confused by earlier errors, bailing out

    Code:
    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;
          }
        }
    Thanks again

  9. #9
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    In the previous else-if block, it appears you need to add a {.
    Code:
    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              
    /*** ADD { HERE ***/
    	  //premium calculation for male
            //35-44 w/ family
            basic_premium = 325.00;
        }
    }
    I'm just guessing this is it...I noticed that it was missing in the previous code that Prelude posted.

  10. #10
    Registered User
    Join Date
    Oct 2002
    Posts
    25
    Hi pianorain,

    Thanks very much, you've been a great help!

    I finally figured out what happened.... I had the brace backward....
    duh.......

    that's the problem with staring the code for hours, it is always one of those tiny little thing that gets you.....

    anyway, thanks so much.. I have a couple more errors that need to be fixed.... I'll see if I can figure them out myself, or else..... I'll be here again....

Popular pages Recent additions subscribe to a feed