Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My second program
#1
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.

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
~ Digital-Punk
Reply


Messages In This Thread
My second program - by Digital-Punk - 12-22-2010, 01:46 PM
RE: My second program - by Scorch - 12-22-2010, 10:21 PM
RE: My second program - by Digital-Punk - 12-22-2010, 10:25 PM
RE: My second program - by Scorch - 12-23-2010, 01:33 AM
RE: My second program - by w00pz - 02-11-2011, 03:42 PM
RE: My second program - by aggouras - 03-09-2011, 09:55 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)