Could use some help (Assignment related)

  • MHB
  • Thread starter WarGhSt
  • Start date
In summary: There is no level " << swimLevel << " completed!" << endl; }}}}In summary, the student entered name is "John", their highest swim level completed is "701", and they want to learn classes "801, 801, 851, 901, 951, 1011, 11
  • #1
WarGhSt
15
0
2nejeVa.png


Code:
#include <iostream>
#include <string>

using namespace std;

int main(){
//    int i = 0;         // Loop counter iterates numRolls times
//    int j = 0;       // loop counter for histogram
    string studentName;  // User defined number of rolls
    int swimLevel = 0;  // Tracks number of 6s found
//    int const classOne = 8; // Entry level Class 8 Skills
//    int const classTwo = 9;      // Class 101 9 Skills
//    int const classThree = 8;      // Class 201 8 Skills
//    int const classFour = 6; // Class 301 6 Skills
//    int const classFive = 7;   // Class 401 7 Skills
//    int const classSix = 7;   // Class 501 7 Skills
//    int const classSeven  = 7;   // Class 601 7 Skills
//    int classUnknown = 10;    cout << "Please enter the name of the student:" << endl;
    cin >> studentName;

    // DEBUG COUT
    //    cout << "Printing student name: " << studentName << "." << endl;

    cout << "Please enter your students highest swim level completed: 1, 101, 201, 301, 401, 501, 601 or '0' to quit" << endl;
    cin >> swimLevel;

    while (swimLevel != 0) {
//    while ((swimLevel == 1) || (swimLevel == 101) || (swimLevel == 201) || (swimLevel == 301) || (swimLevel == 401) || (swimLevel == 501) || (swimLevel == 601)) {

        // DEBUG COUT
    //    cout << "Printing swim level: " << swimLevel << "." << endl;

//        for (i = 0; i < 1; ++i) {
                if (swimLevel == 1) {
                    swimLevel = swimLevel + 1;
                    cout << studentName << " has a total of 0 skills up to level 1!" << endl;
                }
                else if (swimLevel == 101) {
                    swimLevel = swimLevel + 1;
                    cout << studentName << " has a total of 8 skills up to level 101!" << endl;
                }
                else if (swimLevel == 201) {
                    swimLevel = swimLevel + 1;
                    cout << studentName << " has a total of 17 skills up to level 201!" << endl;
                }
                else if (swimLevel == 301) {
                    swimLevel = swimLevel + 1;
                    cout << studentName << " has a total of 25 skills up to level 301!" << endl;
                }
                else if (swimLevel == 401) {
                    swimLevel = swimLevel + 1;
                    cout << studentName << " has a total of 31 skills up to level 401!" << endl;
                }
                else if (swimLevel == 501) {
                    swimLevel = swimLevel +1;
                    cout << studentName << " has a total of 38 skills up to level 501!" << endl;
                }
                else if (swimLevel == 601) {
                    swimLevel = swimLevel +1;
                    cout << studentName << " has a total of 45 skills up to level 601!" << endl;
                }
                else if ((swimLevel != 1) || (swimLevel != 101) || (swimLevel != 201) || (swimLevel != 301) || (swimLevel != 401) || (swimLevel != 501) || (swimLevel != 601))
                      cout << "Remember 1, 101, 201, 301, 401, 501, 601, or 0 to quit!" << endl;
                      cin >> swimLevel;
}
}

My code displays the final result without fail, but does not use the steps for bullet-point 3 & 4 Your program logic must calculate the total number of skill sets inside a loop. For example, if the skill level = 101, then the total will start at 0, then 9 would be added for level 101 and then the 8 would be added in for level 1. If the highest skill level = 201, then the total will start at 0, then 8 would be added for level 201, then 9 would be added for level 101 and then the 8 would be added for level 1 would get added.
The sentinel (or stopping condition of your loop) must be when the skill level goes below 0.


The assignment is already late, so I'm taking a grade penalty there: I'd love to pull off full marks otherwise, so I'm opening my code up to criticism in order to get some help. Also, it should be pointed out that this is the assignment right before learning arrays, so it must be done with while/for loops.
 
Technology news on Phys.org
  • #2
Copy pasted some of the variable definitions from another program at one point - that's why the comments following them don't match up with what the program is doing. Lol
 
  • #3
Okay, I would begin by defining the needed constants and variables:

Code:
#include <iostream>
#include <string>

using namespace std;

int main()
{
	const int Level1 = 8;
	const int Level101 = 9;
	const int Level201 = 8;
	const int Level301 = 6;
	const int Level401 = 7;
	const int Level501 = 7;
	const int Level601 = 7;
	string studentName;
	int swimLevel;
	int quit = 0;

	return 0;
}

Okay, now we are going to want a while loop that executes as long as [M]!quit[/M] (we will set [M]quit = 1[/M] when a zero is input for the swim level), and within this loop we will first ask for the swim level, because it makes no sense to first ask for a name when the user is going to terminate the program by entering a zero, so let's add that:

Code:
#include <iostream>
#include <string>

using namespace std;

int main()
{
	const int Level1 = 8;
	const int Level101 = 9;
	const int Level201 = 8;
	const int Level301 = 6;
	const int Level401 = 7;
	const int Level501 = 7;
	const int Level601 = 7;
	string studentName;
	int swimLevel;
	int swimLevelValid;
	int quit = 0;

	while (!quit)
	{
		swimLevelValid = 0;
		while (!swimLevelValid)
		{
			cout << "Please enter your students highest swim level completed: 1, 101, 201, 301, 401, 501, 601 or '0' to quit" << endl;
			cin >> swimLevel;
			if (swimLevel == 0 || swimLevel == 1 || swimLevel == 101 || swimLevel == 201 || swimLevel == 301 || swimLevel == 401 || swimLevel == 501 || swimLevel == 601)
			{
				swimLevelValid = 1;
			}
			else
			{
				cout << "Invalid swim level completed!" << endl;
			}
		}
		if (!swimLevel)
		{
			quit = 1;
		}
		else
		{
		}
	}

	return 0;
}

Okay, now we have ensured a valid number is entered, and the program will terminate if a zero is entered, so within the else clause we now need to prompt for the student name, and then begin calculating the total number of skills learned based on the input [M]swmiLevel[/M]. Are you with me so far? :)
 
  • #4
Yes, I'm following.
 
  • #5
Okay, the next thing we need to do is prompt the user for the student's name, compute the total skills, and print the results:

Code:
#include <iostream>
#include <string>

using namespace std;

int main()
{
	const int Level1 = 8;
	const int Level101 = 9;
	const int Level201 = 8;
	const int Level301 = 6;
	const int Level401 = 7;
	const int Level501 = 7;
	const int Level601 = 7;
	string studentName;
	int swimLevel;
	int swimLevelValid;
	int quit = 0;
	int i;
	int totalSkills;

	while (!quit)
	{
		swimLevelValid = 0;
		totalSkills = 0;
		while (!swimLevelValid)
		{
			cout << "Please enter your students highest swim level completed: 1, 101, 201, 301, 401, 501, 601 or '0' to quit" << endl;
			cin >> swimLevel;
			if (swimLevel == 0 || swimLevel == 1 || swimLevel == 101 || swimLevel == 201 || swimLevel == 301 || swimLevel == 401 || swimLevel == 501 || swimLevel == 601)
			{
				swimLevelValid = 1;
			}
			else
			{
				cout << "Invalid swim level completed!" << endl;
			}
		}
		if (!swimLevel)
		{
			quit = 1;
		}
		else
		{
			cout << "Please enter the name of the student:" << endl;
			cin >> studentName;
			for (i = (swimLevel - 1)/100; i >= 0; i--)
			{
				switch (i)
				{
					case 6:
						totalSkills += Level601;
						break;
					case 5:
						totalSkills += Level501;
						break;
					case 4:
						totalSkills += Level401;
						break;
					case 3:
						totalSkills += Level301;
						break;
					case 2:
						totalSkills += Level201;
						break;
					case 1:
						totalSkills += Level101;
						break;
					case 0:
						totalSkills += Level1;
						break;
				}
			}
			cout << studentName << " has a total of " << totalSkills << " skills up to level " << swimLevel << "!" << endl;
		}
	}

	return 0;
}
 
  • #6
Going backwards, I can see exactly how all this fits together. Coming up with it on my own, however, is still a long way out!

Thank you very much for the time you spent helping me out!
 

Related to Could use some help (Assignment related)

1. What does "Could use some help (Assignment related)" mean?

This phrase is often used by students or individuals who are struggling with an assignment and are seeking assistance from others. It could mean that they are looking for guidance, clarification, or even someone to collaborate with on the assignment.

2. How do I ask for help on an assignment?

The best way to ask for help on an assignment is to clearly state what you need assistance with and provide any relevant information or materials. It is also important to be respectful and polite when asking for help.

3. Is it okay to ask someone else to do my assignment for me?

No, it is not ethical to ask someone else to do your assignment for you. This goes against academic integrity and can have serious consequences. It is important to seek help and guidance, but ultimately you should be responsible for completing your own assignments.

4. Where can I find reliable help for my assignment?

There are many resources available for students seeking help with assignments. Your first step could be to reach out to your professor or teaching assistant for guidance. You can also seek help from tutors, academic writing centers, or online resources such as educational websites or forums.

5. How can I improve my understanding of the assignment topic?

One of the best ways to improve your understanding of an assignment topic is to do some independent research. This could include reading relevant materials, watching educational videos, or discussing the topic with classmates. It is also helpful to ask for clarification from your professor or teaching assistant if there are any parts of the assignment that you are unsure about.

Similar threads

  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
23
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
Replies
10
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
2
Replies
66
Views
4K
  • Programming and Computer Science
Replies
23
Views
1K
  • Programming and Computer Science
2
Replies
36
Views
2K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top