calculator loop

whats wrong with this??

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

using namespace std;

int main()
{
    int operation;
    int howmany;
    int num;
    int temp;
    int answer;


    cout << "Here are your options: " << endl << endl;
    cout << "1. Addition" << endl;
    cout << "2. Subtraction" << endl;
    cout << "3. Multiplication" << endl;
    cout << "4. Division" << endl;
    cin >> operation;

    switch(operation){

        case 1:

        for (int i=1; i<=num; i++)
{
   cout << "enter how many numbers you want to use"
   cin>>num;
   temp=temp+num;
}

cout<<"The sum of the "<<num<<" numbers is: "<<temp;

cout<<"The sum of the "<<num<<" numbers is: "<<answer;


    }
    cin.get();
    return 0;

}
I guess it's the indentation that's wrong ... The real problem is that you use num before you give it a value
ok i know the indentaion is wrong, im just trying to get it to work. here are the erors:

C:\Users\\Desktop\c++\New folder\a\Untitled2.cpp||In function 'int main()':|
C:\Users\\Desktop\c++\New folder\a\Untitled2.cpp|31|error: a function-definition is not allowed here before '{' token|
C:\Users\\Desktop\c++\New folder\a\Untitled2.cpp|67|error: expected '}' at end of input|
C:\Users\\Desktop\c++\New folder\a\Untitled2.cpp|67|error: expected '}' at end of input|
||=== Build finished: 3 errors, 0 warnings ===|

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

using namespace std;

int main()
{
    int operation;
    int howmany;
    int num;
    int temp;
    int answer;


    cout << "Here are your options: " << endl << endl;
    cout << "1. Addition" << endl;
    cout << "2. Subtraction" << endl;
    cout << "3. Multiplication" << endl;
    cout << "4. Division" << endl;
    cin >> operation;

    switch(operation){

        case 1:
        #include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int operation;
    int howmany;
    int num;
    int temp;
    int answer;


    cout << "Here are your options: " << endl << endl;
    cout << "1. Addition" << endl;
    cout << "2. Subtraction" << endl;
    cout << "3. Multiplication" << endl;
    cout << "4. Division" << endl;
    cin >> operation;

    switch(operation){

        case 1:
        cout << "enter how many numbers you want to use"
        cin>>num;

        for (int i=1; i<=num; i++)
{
    temp=temp+num;
}

cout<<"The sum of the "<<num<<" numbers is: "<<temp;

cout<<"The sum of the "<<num<<" numbers is: "<<answer;


    }
    cin.get();
    return 0;

}

oh i see
wait...something is wrong...when i compile it works...i press 1 to add...i enter how many numbers i want to use....it doesnt let me choose the numbers and just prints a random number on the screen?

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

using namespace std;

int main()
{
    int operation;
    int howmany;
    int num;
    int temp;
    int answer;


    cout << "Here are your options: " << endl << endl;
    cout << "1. Addition" << endl;
    cout << "2. Subtraction" << endl;
    cout << "3. Multiplication" << endl;
    cout << "4. Division" << endl;
    cin >> operation;

    switch(operation){

        case 1:
        cout << "enter how many numbers you want to use";
        cin>>num;

        for (int i=1; i<=num; i++)
{
    temp=temp+num;
}

cout<<"The sum of the "<<num<<" numbers is: "<<temp;

cout<<"The sum of the "<<num<<" numbers is: "<<answer;


    }
    cin.get();
    return 0;

}
The loop only do this temp=temp+num; and temp and answer are both uninitialized so it's not strange that it prints what appears to be random numbers.
so can you please help me fix it
You probably want to input numbers with std::cin inside the loop.
Topic archived. No new replies allowed.