-
-
Save anonymous/f651ee79147eaa5cf438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <iostream> | |
# include <string> | |
# include <cstdlib> | |
void readValue(int& v, const std::string& str) | |
{ | |
std::cout << "Please enter " << str << " and press ENTER: "; | |
std::cin >> v; | |
if( v <= 0) | |
{ | |
std::cout << str << " must be a non-negative value. Try again" << std::endl; | |
readValue(v, str); | |
} | |
} | |
int main() | |
{ | |
std::cout << "This program calculates area" << std::endl; | |
int w; | |
while (42) | |
{ | |
std::cout << "0 to exit; 1 for triangle; 2 for trapeze" << std::endl; | |
std::cin >> w; | |
if (w == 0) break; | |
if (w == 1) | |
{ | |
int a,h; | |
readValue(a, "Base length"); | |
readValue(h, "Vertical height"); | |
std::cout << "Area of triangle is: " << a*h/2. << std::endl; // Дабл, не теряй результат | |
} | |
else if (w == 2) | |
{ | |
int a,b,h; | |
readValue(a, "Base length of A"); | |
readValue(b, "Base length of B"); | |
readValue(h, "Vertical height(h)"); | |
std::cout << "Area of trapeze is:" // У тебя тут Треугольник написано | |
<< (a+b)/2.*h << std::endl; | |
} | |
else std::cout << "Wrong value. Try again." << std::endl; | |
} | |
std::cout << "Thank's for using" << std::endl; | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment