fun program that demonstrates ints

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
#include<iostream>
#include<string>
using namespace std;
double x= 200;
int r=1;
int cowboys()
{
while(x>0)
{
cout<<"x is "<<x;
cout<<"\n";
x=x-0.5;
}
cout<<"\nbye!!\n";
return x;
}
int cowboy()
{
    r=r*2;
    cout<<"Howdeey!!!!!!!!!!!!!!!!!!!!!!!!\"\n";
    return r;
}
int horse()
{
    r=r*2;
    cout<<" Neighhhhhhh!!!!!!!!!!!!!!!!!!!\"\n";
    return r;
}
int ch()
{
    r=r*2;
    cout<<"\n Cowboy says \"";
    cowboy();
    cout<<"\n horse says \"";
    horse();
    return r;
}
int main()
{
    ch();
    cout<<"\n\nThis is what x says \n\n\n\n";
    cowboys();
    cout<<"r is "<<r;
    cout<<"x is "<<x;
    return r;
}
Hey, since you're a beginner I would just like to give you some good tips on how to write better, cleaner, more easily readable code. The biggest thing wrong you did was using global variables. You should almost NEVER use global variables. Instead, keep the variable you need in one function, and pass it around as needed. Second, while you did a good job of breaking up tasks into functions, you could have easily made the horse and cowboy functions as one, by passing a string variable of what they would say. Third, it is very important you comment code. I can not stress how important it is to comment code. Last, keep the formatting of your code the same throughout. You did good with every function except for cowboys. In that function, the layout makes it difficult to tell what code block goes where.
Topic archived. No new replies allowed.