Thread: Finding Letter Grade and Marital Status

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I've not seen the syntax of the argument being used for cin.ignore, nor do I like to use defines, so I have to say that I am suspicious of that context. However, I can't say it won't work either.

    I do know that you are using the switch statement incorrectly.

    I would add iostream.h to your list of includes and you need a
    return type for main(); should be int.

    I would use a different flagging system for the loop to be more efficient. You don't want to print out a student score of -1.

    Code:
    #include <iostream.h>
    
    int main()
    {
      int TestScore, Grade; 
      char Name[15], marStat[15];
      char MarStat; 
      char continue = 'y';
    
      while(continue == 'y')
      {
        cout<<"\n Enter a Student's Name: "; 
        cin.getline(Name,15);
      
        cout<<" Enter Student's Test Score: "; 
        cin>>TestScore;
        cin.ignore(); 
    
    
        if(TestScore < 100 && TestScore >= 90"; 
          Grade=(char)'A' ; break; 
        else if (TestScore < 90 && TestScore >= 80"; 
          Grade=(char)'B' ; break; 
        //etc. 
    
        cout  << " Enter Student's Marital Status: "; 
        cin  >> MarStat;
        cin.ignore(); 
    
       switch(MarStat) 
      { 
         case 'M': case 'm': 
           strcpy(marStat, " Married ");
           break; 
         //etc
       } 
    
      cout<<"\n The Name of the Student: "<<Name; 
      cout<<"\n The Marital Status of the Student: "<< marStat; 
      cout<<"\n The Test Score of the student: "<<TestScore; 
      cout<<"\n The Letter Grade of the student: "<<Grade; 
      
      cout << "To stop at this time enter anything but y:" << end;
      cout << "To continue with another student enter y:" << endl;
      cin >> continue;
     } 
     
      char dummy;
      cin >> dummy;
    
      return 0; 
    }
    Last edited by elad; 03-27-2002 at 10:58 AM.

Popular pages Recent additions subscribe to a feed