- #1
WarGhSt
- 15
- 0
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.