Может можно записать компактней (много условий типа (if))
Всем привет! Предис:только начал осваивать программирование так что может там написано очень плохо и неккоректно, за что прошу прощения ) Появилась идея создать прогу которая будет условно давать 3 вариации одежди от исходной температури. (В будущем хочу подключить сайт для сочитания цветов чтоб и красиво и тд). Я посмотрел что как-то многовато условий типа if(), может и нормально но что-то подсказовает что можно более красиво записать. Сообственно все есть в коде. Заранее спасибо)
#include <iostream>
#include <string>
void main()
{
int a;
std::string b;
const int type = 8;
const int type1 = 2;
int topwear[type][type1]
{ {0,10},
{11,15},
{16,20},
{21,26},
{-26,-21},
{-20,-16},
{-15,-11},
{-10,-1} };
int botwear[type][type1];
std::cout << "\tHello there!\nDont know whats to wear? Let's help you!\nJust write temperature on the window:" << std::endl;
Begining:
std::cin >> a;
Options:
if ((a >= topwear[0][0]) && (a <= topwear[0][1]))
{
std::cout << "Try to wear smt from this:\n1:(op0-10)\n2:(op0-10)\n3:(op0-10)" << std::endl;
}
if ((a >= topwear[1][0]) && (a <= topwear[1][1]))
{
std::cout << "Try to wear smt from this:\n1:(op11-15)\n2:(op11-15)\n3:(op11-15)" << std::endl;
}
if ((a >= topwear[2][0]) && (a <= topwear[2][1]))
{
std::cout << "Try to wear smt from this:\n1:(op16-20)\n2:(op16-20)\n3:(op16-20)" << std::endl;
}
if ((a >= topwear[3][0]) && (a <= topwear[3][1]))
{
std::cout << "Try to wear smt from this:\n1:(op21-26)\n2:(op21-26)\n3:(op21-26)" << std::endl;
}
if ((a >= topwear[4][0]) && (a <= topwear[4][1]))
{
std::cout << "Try to wear smt from this:\n1:\"(-26to-21)\"\n2:\"(-26to-21)\"\n3:\"(-26to-21)\"" << std::endl;
}
if ((a >= topwear[5][0]) && (a <= topwear[5][1]))
{
std::cout << "Try to wear smt from this:\n1:\"(-20to-16)\"\n2:\"(-20to-16)\"\n3:\"(-20to-16)\"" << std::endl;
}
if ((a >= topwear[6][0]) && (a <= topwear[6][1]))
{
std::cout << "Try to wear smt from this:\n1:\"(-15to-11)\"\n2:\"(-15to-11)\"\n3:\"(-15to-11)\"" << std::endl;
}
if ((a >= topwear[7][0]) && (a <= topwear[7][1]))
{
std::cout << "Try to wear smt from this:\n1:\"(-10to-1)\"\n2:\"(-10to-1)\"\n3:\"(-10to-1)\"" << std::endl;
}
}
Всем спасибо и хорошего вечера!