Is my code bad or good?

HI!
Today I would like to know what do you think about the code below:
It's a timer.

Please tell me would you have done something differently?
does the code has something that makes it bad or is it well made?
also what do you think about using the windows.h? should i use(it has some usefull commands that i can use pretty easily(used to program using the batch language)) or is it horrible mistake?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include<ctime>
#include "windows.h"  
using namespace std;

int A1(){  
//I use this function to take the user input and check that it is 1 or 2.
//if its not 1 or 2 it will cause infite loop. to be honest with you this function 
//really does not prefent the infite loop if user input != 2 or 1

int d=0;
for(;;){
    system("CLS");

    int o;
    cout << "Would you like to try again?"<< endl;
    cout << "1.YES!" << endl;
    cout << "2.NO!" << endl;
    cout << "Answer using 1 or 2!" << endl;
    cin >> o;

    switch(o){
    case 1:
    return d;
    case 2:
    d=1;
    return d;
    default:
    cout << "Please use only numbers 1 and 2!" << endl;
    Sleep(1000);
    break;
    }

}

}


int main()
{

for(;;)
{
system("CLS");
cout << "Press anykey to start the timer!" << endl;
system("PAUSE > NUL");
    int x = time(0); // starting time
    system("CLS");
    cout << "Press anykey to stop the timer!" << endl;
system("PAUSE > NUL");
    int y = time(0); // ending time
    system("CLS");
    int c = y-x; // the time that has passed
    int a=c/60; 

//minutes if has it will be 1 else 0. because int can only have whole numbers

    int b= a/60; // hours using the same tecnig;D

    if(a>0&&b==0){  // if minutes have passed
        c=c-60*a;  // this prevents the program out put being something like 1:99
    cout << "time that has passed: 00:" << a << ":" << c << endl;

    }

    else if(a==0&&b==0){  // if only seconds have passed
    cout << "time that has passed: 00:00:" << c << endl;
    }

    else if(b>0){
        a=a-60*b; // prevents the out put being 1:78:99
        c=c-60*a; // prevents the out put being 1:78:99
    cout << "time that has passed:" << b << ":" << a << ":" << c << endl;
    }

    Sleep(1500);
    system("CLS");
    int e=A1();
    if(e == 1)
    {
     break;
    }


}
}




so what you think about the code is it bad or good?
did i do something wrong?
the reason why I'am asking this because someone disliked my code with out telling me a reason so i just want to know if he's a troll or if my code really sucks?
Last edited on
System calls are frowned upon.
http://www.cplusplus.com/articles/j3wTURfi/

Your variable names are meaningless. b, a and c signifiy hours, minutes and seconds, so why not name them that way?

Other than that, the code doesn't really do much, so there isn't much to discuss. Try a larger project; usually, "bad code" will come back to haunt you anyway.
Good spacing, make sure you prototype your functions. When you write large programs with functions calling other functions, it can be a huge pain if the compiler doesn't recognize the functions.
Topic archived. No new replies allowed.