473,466 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Loop Problem

32 New Member
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_adjustParticipation function to run either. Everytime I run it, it loops the same amount of times as the first loop.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. double examContrib(double exam, char status);
  4. double assignContrib(double assign, char status);
  5. double on_campus_examContrib(double exam);
  6. double online_examContrib(double exam);
  7. double on_campus_assignContrib(double assign);
  8. double online_assignContrib(double assign);
  9. double adjustParticip(double adjust, char status);
  10. double on_campus_adjustParticipation(double adjust);
  11. double online_adjustParticipation(double adjust);
  12. int main()
  13. {
  14.     char status;
  15.     double adjust, assign, exam, course_score = 0;
  16.  
  17.     cout << "Enter C for on-campus or L for online" << endl;
  18.     cin >> status;
  19.     while ( status != 'C'&& status != 'L'){
  20.         cout << "Enter again" << endl;
  21.         cin >> status;
  22.     }
  23.     for (int i=0; i <4; i++){
  24.         cout << "Enter the exam score" <<endl;
  25.         cin >> exam;
  26.         course_score = course_score + examContrib(exam, status);
  27.         cout << course_score << endl;
  28.     }
  29.  
  30.     for (int b=0; b<5; b++){
  31.         cout << "Enter the assignment score" << endl;
  32.         cin >> assign;
  33.         course_score = course_score + assignContrib(assign, status);
  34.         cout << course_score <<endl;
  35.  
  36.     }
  37.  
  38.     while(status == 'C'){
  39.         cout << "Enter the participation for on campus students" << endl;
  40.         cin >> status;
  41.         cout << on_campus_adjustParticipation(adjust)<< endl;
  42.     }
  43.  
  44.     while(status == 'L'){
  45.         cout << "Enter the participation for online students" << endl;
  46.         cin >> status;
  47.         cout << online_adjustParticipation(adjust) << endl;
  48.     }
  49.  
  50.         return 0;
  51. }
  52.  
  53.     double examContrib(double exam, char status){
  54.         double score;
  55.         if (status == 'C'){
  56.             score = on_campus_examContrib(exam);
  57.         }
  58.         if (status == 'L'){
  59.             score = online_examContrib(exam);
  60.         }
  61.  
  62.         return score;
  63.     }
  64.  
  65.  
  66.     double on_campus_examContrib(double exam){
  67.         double score;
  68.         score = (exam *.10);
  69.         return score;
  70.     }
  71.  
  72.     double online_examContrib(double exam){
  73.         double score;
  74.         score = (exam * .15);
  75.         return score;
  76.     }
  77.  
  78.     double assignContrib(double assign, char status){
  79.         double score;
  80.         if (status == 'C'){
  81.             score = on_campus_assignContrib(assign);
  82.         }
  83.         if (status == 'L'){
  84.             score = online_assignContrib(assign);
  85.         }
  86.  
  87.         return score; 
  88.         }
  89.  
  90.     double on_campus_assignContrib(double assign){
  91.         double score;
  92.         score = (assign * .12);
  93.         return score;
  94.         }
  95.  
  96.         double online_assignContrib(double assign){
  97.             double score;
  98.             score = (assign *.13);
  99.             return score;
  100.         }
  101.  
  102.     double adjustParticip(double adjust, char status){
  103.         double evaluation;
  104.         if (status == 'C'){
  105.             evaluation = on_campus_adjustParticipation(adjust);
  106.         }
  107.         if (status == 'L'){
  108.             evaluation = online_adjustParticipation(adjust);
  109.         }
  110.  
  111.         return evaluation;
  112.     }
  113.  
  114.     double on_campus_adjustParticipation(double adjust){
  115.         if (adjust <= 4){
  116.             return 1;
  117.         }
  118.          if(adjust <= 7){
  119.             return 1.04;
  120.          }
  121.          if (adjust >= 8){
  122.              return 1.08;
  123.          }
  124.     }
  125.  
  126.     double online_adjustParticipation(double adjust){
  127.         if (adjust <= 3){
  128.             return 1;
  129.         }
  130.         if (adjust <= 6){
  131.             return 1.02;
  132.         }
  133.         if (adjust <= 9){
  134.             return 1.05;
  135.         }
  136.         if (adjust = 10){
  137.             return 1.08;
  138.         }
  139.     }
Feb 21 '07 #1
4 1259
willakawill
1,646 Top Contributor
Expand|Select|Wrap|Line Numbers
  1. while(status == 'C'){
  2.         cout << "Enter the participation for on campus students" << endl;
  3.         cin >> status;
  4.         cout << on_campus_adjustParticipation(adjust)<< endl;
  5.     }
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.
Feb 21 '07 #2
compsci
32 New Member
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_adjustParticipation, for ‘L’, it delegates to online_ adjustParticipation,.
• 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:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. double examContrib(double exam, char status);
  4. double assignContrib(double assign, char status);
  5. double on_campus_examContrib(double exam);
  6. double online_examContrib(double exam);
  7. double on_campus_assignContrib(double assign);
  8. double online_assignContrib(double assign);
  9. double adjustParticip(double adjust, char status);
  10. double on_campus_adjustParticipation(double adjust);
  11. double online_adjustParticipation(double adjust);
  12. int main()
  13. {
  14.     //These are my variables
  15.     char status;
  16.     double adjust = 0, assign, exam, course_score = 0;
  17.  
  18.     //This is is where the user inputs either a C or L.
  19.     cout << "Enter C for on-campus or L for online" << endl;
  20.     cin >> status;
  21.     while ( status != 'C'&& status != 'L'){
  22.         cout << "Enter again" << endl;
  23.         cin >> status;
  24.     }
  25.     //This is the for loop for when the user enters the exams
  26.     for (int i=0; i <4; i++){
  27.         cout << "Enter the exam score" <<endl;
  28.         cin >> exam;
  29.         course_score = course_score + examContrib(exam, status);
  30.         cout << course_score << endl;
  31.     }
  32.     //This is the loop for when the user enters the assignments
  33.     for (int b=0; b<5; b++){
  34.         cout << "Enter the assignment score" << endl;
  35.         cin >> assign;
  36.         course_score = course_score + assignContrib(assign, status);
  37.         cout << course_score <<endl;
  38.  
  39.     }
  40.     // This is the part that I'm not sure about
  41.  
  42.     for (int i=0; i <4; i++){
  43.  
  44.         cout << "Enter the participation for on campus students" << endl;
  45.         cin >> adjust;
  46.         evaluation = 
  47.         cout << adjustParticip(adjust, status)<< endl;
  48.     }
  49.  
  50.     for (int b=0; b<5; b++){
  51.         cout << "Enter the participation for online students" << endl;
  52.         cin >> adjust;
  53.         cout << adjustParticip(adjust, status) << endl;
  54.     }
  55.  
  56.         return 0;
  57. }
  58. //These are some of my function needed for the program.
  59.  
  60.     double examContrib(double exam, char status){
  61.         double score;
  62.         if (status == 'C'){
  63.             score = on_campus_examContrib(exam);
  64.         }
  65.         if (status == 'L'){
  66.             score = online_examContrib(exam);
  67.         }
  68.  
  69.         return score;
  70.     }
  71.  
  72.  
  73.     double on_campus_examContrib(double exam){
  74.         double score;
  75.         score = (exam *.10);
  76.         return score;
  77.     }
  78.  
  79.     double online_examContrib(double exam){
  80.         double score;
  81.         score = (exam * .15);
  82.         return score;
  83.     }
  84.  
  85.     double assignContrib(double assign, char status){
  86.         double score;
  87.         if (status == 'C'){
  88.             score = on_campus_assignContrib(assign);
  89.         }
  90.         if (status == 'L'){
  91.             score = online_assignContrib(assign);
  92.         }
  93.  
  94.         return score; 
  95.         }
  96.  
  97.     double on_campus_assignContrib(double assign){
  98.         double score;
  99.         score = (assign * .12);
  100.         return score;
  101.         }
  102.  
  103.         double online_assignContrib(double assign){
  104.             double score;
  105.             score = (assign *.13);
  106.             return score;
  107.         }
  108.  
  109.     double adjustParticip(double adjust, char status){
  110.         double evaluation;
  111.         if (status == 'C'){
  112.             evaluation = on_campus_adjustParticipation(adjust);
  113.         }
  114.         if (status == 'L'){
  115.             evaluation = online_adjustParticipation(adjust);
  116.         }
  117.  
  118.         return evaluation;
  119.     }
  120.  
  121.     double on_campus_adjustParticipation(double adjust){
  122.         if (adjust <= 4){
  123.             return 1;
  124.         }
  125.          if(adjust <= 7){
  126.             return 1.04;
  127.          }
  128.          if (adjust >= 8){
  129.              return 1.08;
  130.          }
  131.     }
  132.  
  133.     double online_adjustParticipation(double adjust){
  134.         if (adjust <= 3){
  135.             return 1;
  136.         }
  137.         if (adjust <= 6){
  138.             return 1.02;
  139.         }
  140.         if (adjust <= 9){
  141.             return 1.05;
  142.         }
  143.         if (adjust = 10){
  144.             return 1.08;
  145.         }
  146.     }
Feb 22 '07 #3
willakawill
1,646 Top Contributor
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 :)
Feb 22 '07 #4
compsci
32 New Member
Okay I'm ready
Feb 22 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
5
by: build | last post by:
G'day All, I have a problem with this loop. There are a number of .txt files in 'myPath'. tmpFile = Dir(myPath & "\*.txt") 'PROCESS FOLDER Do Until tmpFile = "" <lottsa code> <too much to...
11
by: ritterhaus | last post by:
Just a simple bit of code to toggle between two state at intervals... import time for i in range(4): print 'On' time.sleep(1) print 'Off' time.sleep(1) .... SHOULD toggle On and Off four...
12
by: reynoldscraigr | last post by:
Hi All, hope someone can see what wrong here I have the following function function RemoveMenuFromHoldArray(menuName) { var i = 0; for (i=0;i<=MenusToHoldOpen.length-1;i++) { if...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
63
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
15
by: Mike Lansdaal | last post by:
I came across a reference on a web site (http://www.personalmicrocosms.com/html/dotnettips.html#richtextbox_lines ) that said to speed up access to a rich text box's lines that you needed to use a...
2
by: d3vkit | last post by:
Okay so I can NOT get my while loop to work. It's the most confusing thing I've ever come across. It was working fine and then suddenly, nothing. No error. The page just dies. I am using PHP5 with...
5
by: sgurukrupagmailcom | last post by:
Hi, I haven't come accross an elegant solution to a design problem that I show below. Have a look at the piece of code here: class Exc { Exc () { System.out.println ("Haribol"); }
1
by: JavaJon | last post by:
Hello, I'm Jon. I've recently picked up Java after using a "gimmick" programming language called GML ( Game Maker Language ). I've read a lot of tutorials and even a Java for Dummies *.pdf book....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.