Ideas for a new guy

So basically i just started out with this language not too long ago (maybe a week and a half), and I was hoping to get some ideas of what I should try creating as far as a console application goes. I've done a calculator, but that's as much as my current skills go, and even then it would not have been possible without following along with a youtube tutorial. Also where should I continue as far as lessons go? I don't understand arrays very well but can manage with declaring variables and some other very basic concepts. Oh, and here's the calculator if there's any suggestions to improve.

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
  #include <cstdlib>
#include <iostream>

using namespace std;

float addition(float num1, float num2)
{
    return num1 + num2;
}
float subtraction(float num1, float num2)
{
    return num1 - num2;
}
float multiplication(float num1, float num2)
{
    return num1 * num2;
}
float division(float num1, float num2)
{
    return num1 / num2;
}

int main()
{
    float num1;
    float num2;
    int choice;
    cout<<"Choose your operation, 1= add, 2=subtract, 3=multiply, 4=divide" <<endl;
    cout<<"Choice: ";
    cin>>choice;
    if(choice==1)
    {
                //Addition section
        cout<<"you are adding, please enter the first number you would like to add. \n Number 1: ";
        cin>>num1;
        cout<<"please enter the second number you would like to add. \n Number 2: ";
        cin>>num2;
        cout<< "The answer is " << addition(num1, num2) <<endl;
    }
    else
    {
        if(choice==2)
        {
               //Subraction
        cout<<"you are now subtraction, please enter the first number. \n Number 1: ";
        cin>>num1;
        cout<<"enter the next number. \n Number 2: ";
        cin>>num2;
        cout<< "the answer is: " << subtraction(num1, num2) <<endl;          
        }
        
        else
            if(choice==3)
        {
                   //Multiplying
        cout<<"you are multiplying, enter the first number. \n Number 1: ";
        cin>>num1;
        cout<<"please enter the second number. \n Number 2: ";
        cin>>num2;
        cout<<"the answer is: " <<multiplication(num1, num2) <<endl; 
        }
        else
            if(choice==4)
            {
               //division
        cout<<"you are dividing, enter the first number. \n Number 1: ";
        cin>>num1;
        cout<<"enter the second number. \n Number 2: ";
        cin>>num2;
        cout<<"the answer is: "<<division(num1, num2)<<endl<<endl;             
            }
        
    }
    
     
    system("PAUSE");
    return 0;
}
Why so complicated? I wouldn't use functions and all that complicated stuff if I didn't know what they were. In my eyes, this would be much, much easier

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main () {
int num1, num2, choice;
cout << "Choose your operation: 1 add, 2 substract, 3 divide, 4 multiply"; 
cin >> choice;
cout << "Enter first number..." << endl;
cin >> num1;
cout << "Enter second number..." << endl;
cin >> num2;
if (choice == 1 ) 
cout <<  "the result is " << num1 + num2;
if (choice ==2)
cout <<  "the result is " << num1 - num2;
if (choice ==3)
cout <<  "the result is " << (double)num1 / num2;
if (choice ==4) 
cout << "the result is " << num1 * num2;
cin.get();
cin.ignore();
return 0;
}


Also, I suggest not learning anything new (arrays are complicated) until you understand basics : if statements and loops.
For cleaner code and more control, a switch method would be useful here for lines between 31 - 73. This isn't necessary as your program works great, just a good method to know. Read up on switches here: http://www.cplusplus.com/doc/tutorial/control/

For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
	switch (choice) {
		case 1:
			cout << "This is what happens if choice == 1";
			break;
		case 2:
			cout << "This is what happens if choice == 2";
			break;
		case 3:
			etc....
                        break;
		default:
			cout << "This is what happens if choice does not equal 1-3.";
	}
Last edited on
why don't you try to create a simple text-based RPG? that would use variables, conditions, and basic text input-output.

then, go for loops ("for" and "while").
@uzferry-I've taken your advice and am sticking to more basics for a little while.
@rcast- thanks! Reading that page currently.
@stauricus- will do.

Any programs I should attempt making besides a text based RPG?
Topic archived. No new replies allowed.