You could've used std::vector<>
for storing multiple struct types using a single variable.
Look at the following:
#include <iostream>
#include <vector>
struct Malware {
std::string name;
bool danger;
};
void getMalwareDetails(Malware); // parameter: struct
int main(void) {
std::vector<Malware> malware; // HERE'S WHAT I'M TALKING ABOUT
Malware mTemp; // for temporary
char ask;
do {
std::cout << "Malware name and is that danger (1/0)? : ";
std::cin >> mTemp.name >> mTemp.danger;
malware.push_back(mTemp); // adds the info to struct
std::cout << "Add more? (Y/n): ";
std::cin >> ask;
} while (ask == 'Y' || ask == 'y');
for (int i = 0; i < malware.size(); i++)
getMalwareDetails(malware[i]); // get the struct info
return 0;
}
void getMalwareDetails(Malware m) {
std::cout << "Name: " << m.name << " Danger?: " << m.danger << std::endl;
}
Create a struct
, use std::vector<STRUCT_NAME>
, add the struct values to the vector variable on each iteration then finally display them. Similarly, you may use one more struct for DDos
.
Sample Output
Malware name and is that danger? : $DDoSThreat% 1 // --- INPUT
Add more? (Y/n): y
Malware name and is that danger? : Trojan 1
Add more? (Y/n): y
Malware name and is that danger? : Google 0
Add more? (Y/n): n
Name: $DDoSThreat% Danger?: 1 // --- OUTPUT
Name: Trojan Danger?: 1
Name: Google Danger?: 0