1
0

Compare commits

..

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

View File

@ -1,60 +1,21 @@
#include <iostream>
using string = std::string;
void ignoreTillLineEnd();
string promptfs(string);
int promptfi(string);
int getValue()
{
std::cout << "Enter an integer: ";
int x{};
std::cin >> x;
return x;
}
int main()
{
int nameC {promptfi("Enter the number of names:")};
if (nameC < 1) {
std::cout << "No names to be entered!\n";
return 1;
}
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";
int a{ getValue() };
int b{ getValue() };
int c{ getValue() };
std::cout << a + (b * c); // order of eval doesn't matter now
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;
}