I need a way to compare a number to the amount of times a string was entered. In my project i need to make sure that when a category for a bunch is selected like 'P' for pretty_category or 's' for so_category, it is not greater than the number the user said was already in that specific category in the beginning of the program.
Code:
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
int num_check(int num);
int num_check2(int num2);
int main() {
int w = 0, x = 0, y = 0, z = 0;
int pretty_category, so_category, ugly_category;
int category;
string type1,type2,type3,type4,type5;
cout << "How many flowers are in the Pretty Category?" << endl;
pretty_category = num_check(x);
cout << "How many flowers are in the So-So Category?" << endl;
so_category = num_check(y);
cout << "How many flowers are in the Ugly Category?" << endl;
ugly_category = num_check(z);
cout << "How many categories are in this basket" << endl;
category = num_check2(w);
if (category == 1) {
cout << "What category for the 1st bunch: " << endl;
cin >> type1;
}
else if (category == 2) {
cout << "What category for the 1st bunch: " << endl;
cin >> type1;
cout << "What category for the 2nd bunch: " << endl;
cin >> type2;
}
else if (category == 3) {
cout << "What category for the 1st bunch: " << endl;
cin >> type1;
cout << "What category for the 2nd bunch: " << endl;
cin >> type2;
cout << "What category for the 1st bunch: " << endl;
cin >> type3;
}
else if (category == 4) {
cout << "What category for the 1st bunch: " << endl;
cin >> type1;
cout << "What category for the 2nd bunch: " << endl;
cin >> type2;
cout << "What category for the 1st bunch: " << endl;
cin >> type3;
cout << "What category for the 1st bunch: " << endl;
cin >> type4;
}
else if (category == 5){
cout << "What category for the 1st bunch: " << endl;
cin >> type1;
cout << "What category for the 2nd bunch: " << endl;
cin >> type2;
cout << "What category for the 1st bunch: " << endl;
cin >> type3;
cout << "What category for the 1st bunch: " << endl;
cin >> type4;
cout << "What category for the 1st bunch: " << endl;
cin >> type5;
}
system("pause");
return 0;
}
int num_check(int num) {
cin >> num;
while (num < 0) {
cout << "Error try again" << endl;
cin >> num;
}
return num;
}
int num_check2(int num2) {
cin >> num2;
while (num2 < 1 || num2>5) {
cout << "Error try again" << endl;
cin >> num2;
}
return num2;
}