Loop Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compsci
    New Member
    • Jan 2007
    • 32

    Loop Problem

    While the status is at C or L, I want the user to input the participation and print it to the screen. I can't get my online_adjustPa rticipation function to run either. Everytime I run it, it loops the same amount of times as the first loop.

    Code:
    #include <iostream>
    using namespace std;
    double examContrib(double exam, char status);
    double assignContrib(double assign, char status);
    double on_campus_examContrib(double exam);
    double online_examContrib(double exam);
    double on_campus_assignContrib(double assign);
    double online_assignContrib(double assign);
    double adjustParticip(double adjust, char status);
    double on_campus_adjustParticipation(double adjust);
    double online_adjustParticipation(double adjust);
    int main()
    {
    	char status;
    	double adjust, assign, exam, course_score = 0;
    	
    	cout << "Enter C for on-campus or L for online" << endl;
    	cin >> status;
    	while ( status != 'C'&& status != 'L'){
    		cout << "Enter again" << endl;
    		cin >> status;
    	}
    	for (int i=0; i <4; i++){
    		cout << "Enter the exam score" <<endl;
    		cin >> exam;
    		course_score = course_score + examContrib(exam, status);
    		cout << course_score << endl;
    	}
    	
    	for (int b=0; b<5; b++){
    		cout << "Enter the assignment score" << endl;
    		cin >> assign;
    		course_score = course_score + assignContrib(assign, status);
    		cout << course_score <<endl;
    		
    	}
    
    	while(status == 'C'){
    		cout << "Enter the participation for on campus students" << endl;
    		cin >> status;
    		cout << on_campus_adjustParticipation(adjust)<< endl;
    	}
    	
    	while(status == 'L'){
    		cout << "Enter the participation for online students" << endl;
    		cin >> status;
    		cout << online_adjustParticipation(adjust) << endl;
    	}
    		
    		return 0;
    }
    
    	double examContrib(double exam, char status){
    		double score;
    		if (status == 'C'){
    			score = on_campus_examContrib(exam);
    		}
    		if (status == 'L'){
    			score = online_examContrib(exam);
    		}
    	
    		return score;
    	}
    	
    		
    	double on_campus_examContrib(double exam){
    		double score;
    		score = (exam *.10);
    		return score;
    	}
    	
    	double online_examContrib(double exam){
    		double score;
    		score = (exam * .15);
    		return score;
    	}
    	
    	double assignContrib(double assign, char status){
    		double score;
    		if (status == 'C'){
    			score = on_campus_assignContrib(assign);
    		}
    		if (status == 'L'){
    			score = online_assignContrib(assign);
    		}
    		
    		return score; 
    		}
    		
    	double on_campus_assignContrib(double assign){
    		double score;
    		score = (assign * .12);
    		return score;
    		}
    		
    		double online_assignContrib(double assign){
    			double score;
    			score = (assign *.13);
    			return score;
    		}
    		
    	double adjustParticip(double adjust, char status){
    		double evaluation;
    		if (status == 'C'){
    			evaluation = on_campus_adjustParticipation(adjust);
    		}
    		if (status == 'L'){
    			evaluation = online_adjustParticipation(adjust);
    		}
    		
    		return evaluation;
    	}
    	
    	double on_campus_adjustParticipation(double adjust){
    		if (adjust <= 4){
    			return 1;
    		}
    		 if(adjust <= 7){
    			return 1.04;
    		 }
    		 if (adjust >= 8){
    		 	return 1.08;
    		 }
    	}
    		 
    	double online_adjustParticipation(double adjust){
    		if (adjust <= 3){
    			return 1;
    		}
    		if (adjust <= 6){
    			return 1.02;
    		}
    		if (adjust <= 9){
    			return 1.05;
    		}
    		if (adjust = 10){
    			return 1.08;
    		}
    	}
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Code:
    while(status == 'C'){
    		cout << "Enter the participation for on campus students" << endl;
    		cin >> status;
    		cout << on_campus_adjustParticipation(adjust)<< endl;
    	}
    Hi. I think this is the part of your code you are referring to. You are asking for the student to enter the participation and you are recording that as the status. Then you are passing adjust as a parameter when adjust has been given no value. I expect you wanted to assign the input to adjust and not to status. Another thing to think about is, assuming my guess above is correct, if the user enters 7.5 you have no return value that applies to this function and, finally, this while loop is infinite if my guess is correct.

    Comment

    • compsci
      New Member
      • Jan 2007
      • 32

      #3
      I am trying to make functions of the following:
      • adjustParticip returns the adjustment factor reflecting the student’s class participation. It is passed the 0-10 evaluation of the student’s class participation as well as a character ‘C’ or ‘L’. For ‘C’, it delegates to on_campus_adjus tParticipation, for ‘L’, it delegates to online_ adjustParticipa tion,.
      • score2letter is passed a numerical course score and returns the corresponding letter grade. (This does not delegate its work since this conversion is the same for on-campus and online students.)

      I have tried to do the adjustparticip function but it is not running right. It functon continues to loop.. For an on-campus student, the factor for adjusting the course score is 1 if his/her participation score is 4 or less, it is 1.04 if his/her participation score is from 5 to 7, and it is 1.08 if this score is 8 or more. For an online student, the factor is 1 if his/her participation score is 3 or less, 1.02 if this score is from 4 to 6, 1.05 if this score is from 7 to 9, and 1.08 if this score is 10.

      I dont know how to start on the score2letter function. Th e function is suppose to compute the letter grade from the adjusted course score. A score of 90 or above (because of the adjustment, the score might be over 100) is an A, 80 up to (but not including) 90 is a B, 70 up to (but not including) 80 is a C, 60 up to (but not including) 70 is a D, and anything below a 60 is an F.

      This is what I have so far:
      Code:
      #include <iostream>
      using namespace std;
      double examContrib(double exam, char status);
      double assignContrib(double assign, char status);
      double on_campus_examContrib(double exam);
      double online_examContrib(double exam);
      double on_campus_assignContrib(double assign);
      double online_assignContrib(double assign);
      double adjustParticip(double adjust, char status);
      double on_campus_adjustParticipation(double adjust);
      double online_adjustParticipation(double adjust);
      int main()
      {
      	//These are my variables
      	char status;
      	double adjust = 0, assign, exam, course_score = 0;
      	
      	//This is is where the user inputs either a C or L.
      	cout << "Enter C for on-campus or L for online" << endl;
      	cin >> status;
      	while ( status != 'C'&& status != 'L'){
      		cout << "Enter again" << endl;
      		cin >> status;
      	}
      	//This is the for loop for when the user enters the exams
      	for (int i=0; i <4; i++){
      		cout << "Enter the exam score" <<endl;
      		cin >> exam;
      		course_score = course_score + examContrib(exam, status);
      		cout << course_score << endl;
      	}
      	//This is the loop for when the user enters the assignments
      	for (int b=0; b<5; b++){
      		cout << "Enter the assignment score" << endl;
      		cin >> assign;
      		course_score = course_score + assignContrib(assign, status);
      		cout << course_score <<endl;
      		
      	}
      	// This is the part that I'm not sure about
      
      	for (int i=0; i <4; i++){
      		
      		cout << "Enter the participation for on campus students" << endl;
      		cin >> adjust;
      		evaluation = 
      		cout << adjustParticip(adjust, status)<< endl;
      	}
      	
      	for (int b=0; b<5; b++){
      		cout << "Enter the participation for online students" << endl;
      		cin >> adjust;
      		cout << adjustParticip(adjust, status) << endl;
      	}
      		
      		return 0;
      }
      //These are some of my function needed for the program.
      
      	double examContrib(double exam, char status){
      		double score;
      		if (status == 'C'){
      			score = on_campus_examContrib(exam);
      		}
      		if (status == 'L'){
      			score = online_examContrib(exam);
      		}
      	
      		return score;
      	}
      	
      		
      	double on_campus_examContrib(double exam){
      		double score;
      		score = (exam *.10);
      		return score;
      	}
      	
      	double online_examContrib(double exam){
      		double score;
      		score = (exam * .15);
      		return score;
      	}
      	
      	double assignContrib(double assign, char status){
      		double score;
      		if (status == 'C'){
      			score = on_campus_assignContrib(assign);
      		}
      		if (status == 'L'){
      			score = online_assignContrib(assign);
      		}
      		
      		return score; 
      		}
      		
      	double on_campus_assignContrib(double assign){
      		double score;
      		score = (assign * .12);
      		return score;
      		}
      		
      		double online_assignContrib(double assign){
      			double score;
      			score = (assign *.13);
      			return score;
      		}
      		
      	double adjustParticip(double adjust, char status){
      		double evaluation;
      		if (status == 'C'){
      			evaluation = on_campus_adjustParticipation(adjust);
      		}
      		if (status == 'L'){
      			evaluation = online_adjustParticipation(adjust);
      		}
      		
      		return evaluation;
      	}
      	
      	double on_campus_adjustParticipation(double adjust){
      		if (adjust <= 4){
      			return 1;
      		}
      		 if(adjust <= 7){
      			return 1.04;
      		 }
      		 if (adjust >= 8){
      		 	return 1.08;
      		 }
      	}
      		 
      	double online_adjustParticipation(double adjust){
      		if (adjust <= 3){
      			return 1;
      		}
      		if (adjust <= 6){
      			return 1.02;
      		}
      		if (adjust <= 9){
      			return 1.05;
      		}
      		if (adjust = 10){
      			return 1.08;
      		}
      	}

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        OK. We can continue with this and get it to work or just nip it in the bud. This depends on you responding to my posts and the two of us working together on the problem, which I am more than happy to do if I get the idea that you are playing along.

        So the first step is for you to read my last post and respond only to what I posted. Do not add any other information or code. One step at a time :)

        Comment

        • compsci
          New Member
          • Jan 2007
          • 32

          #5
          Okay I'm ready

          Comment

          Working...