1
0

Compare commits

..

No commits in common. "a9b58871c077ecd1e161fd818b40dd406a3914d2" and "c904f740b7f41b6541f116e8cde5d50f400c943e" have entirely different histories.

View File

@ -1,60 +1,21 @@
#include <iostream> #include <iostream>
using string = std::string; int getValue()
void ignoreTillLineEnd(); {
string promptfs(string); std::cout << "Enter an integer: ";
int promptfi(string);
int x{};
std::cin >> x;
return x;
}
int main() int main()
{ {
int nameC {promptfi("Enter the number of names:")}; int a{ getValue() };
if (nameC < 1) { int b{ getValue() };
std::cout << "No names to be entered!\n"; int c{ getValue() };
return 1;
} std::cout << a + (b * c); // order of eval doesn't matter now
string* names = new string[nameC];
for (int i = 0; i < nameC; i++) names[i] = promptfs("Enter your name:");
std::cout << "I have " << nameC << " to say hello to!\n";
for (int i = 0; i < nameC; i++) std::cout << "Hello " << names[i] << ".\n";
return 0; return 0;
} }
void ignoreTillLineEnd() {
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
string promptfs(string msg) {
bool once {false};
string toret {};
do {
if (once) {
std::cin.clear();
ignoreTillLineEnd();
std::cout << "Input Failure!\n";
}
std::cout << msg << "\n";
std::cin >> toret;
once = true;
}
while (std::cin.fail());
ignoreTillLineEnd();
return toret;
}
int promptfi(string msg) {
bool once {false};
int toret {};
do {
if (once) {
std::cin.clear();
ignoreTillLineEnd();
std::cout << "Input Failure!\n";
}
std::cout << msg << "\n";
std::cin >> toret;
once = true;
}
while (std::cin.fail());
ignoreTillLineEnd();
return toret;
}