12-22-2010, 01:46 PM
This my second program it is pretty useless. Im learning c++ and Im just doing random exercises. It is a statistics generator, so far not many statistics just the basics lol. I dont really like the if structure I think there could of been a better way to do it. Anyway let me know what you guys think of the code. And if there would be anything to add to the statistics of two numbers.
Thanks,
Algorithm
Code:
#include <iostream>
#include <Windows.h>
#include <math.h>
void stat(float,float);
int main()
{
float x,y;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
std::cout << "Enter a number: ";
std::cin >> x;
std:: cout << "Enter another number: ";
std::cin >> y;
std::cout << std::endl;
stat(x,y);
std::cin.ignore();
std::cin.get();
return 0;
}
void stat(float x, float y)
{
float result [5];
result[0] = x+y;
result[1] = x-y;
result[2] = x*y;
result[3] = x/y;
result[4] = pow(x,y);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
std::cout << "Printing statistics......" << std::endl << std::endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
std::cout << x << " + " << y << " = " << result[0] << std::endl;
std::cout << x << " - " << y << " = " << result[1] << std::endl;
std::cout << x << " * " << y << " = " << result[2] << std::endl;
std::cout << x << " / " << y << " = " << result[3] << std::endl;
std::cout << x << " ^ " << y << " = " << result[4] << std::endl << std::endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
if (x<y) std::cout << x << " < " << y << " = " << "true\n";
else std::cout << x << " < " << y << " = " << "false\n";
if (x>y) std::cout << x << " > " << y << " = " << "true\n";
else std::cout << x << " > " << y << " = " << "false\n";
if (x==y) std::cout << x << " == " << y << " = " << "true\n";
else std::cout << x << " == " << y << " = " << "false\n";
}
Thanks,
Algorithm