x was not declared in the scope.

Write your question here.

Hi there. I'm practising calculators, and I have trouble to make it work every time. The second code I inserted here to show you, works fine. But not the code above. And they seem like the same? I get the message: "skapatal1" and "skapatal2" was not declared in the scope.. what? it works just fine in the other code... would be so happy to be able to understand what I'm doing wrong.

the human language in the code is swedish :I

/F

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



using namespace std;

//THIS DOESN'T WORK, "skapatal1" and "skapatal2" was not declared in the scope..

    int minfunktionmulti (tal1, tal2)
{

    return tal1 * tal2;
}

int main ()
{

    int skapatal;
    int skapatal2;

    cout << "skriv in ett tal tack" << endl;
    cin >> skapatal;
    cout << "and another one pls" << endl;
    cin >> skapatal2;
    cout << "detta er summan" << minfunktionmulti (tal1, tal2) << endl;

    return 0;
}

//The code below WORKS

using namespace std;

    int addition (int skrivtal, int skrivtaltill)
{
    return skrivtal + skrivtaltill;

}

int main()
{
      int skrivtal;
      int skrivtaltill;

      cout << "skriv tal" << endl;
      cin >> skrivtal;
      cout << "skriv ett till tal" << endl;
      cin >> skrivtaltill;
      cout << "summan av ditt tal, addition ar" << addition (skrivtal, skrivtaltill) << endl;

      return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    int minfunktionmulti (tal1, tal2)
{

    return tal1 * tal2;
}

int main ()
{

    int skapatal;
    int skapatal2;

    cout << "skriv in ett tal tack" << endl;
    cin >> skapatal;
    cout << "and another one pls" << endl;
    cin >> skapatal2;
    cout << "detta er summan" << minfunktionmulti (tal1, tal2) << endl;


1. In the declaration of minfunktionmulti paraemeters; types were not specified.
2. In main variables ral1 and tal2 were not defined. So the call

minfunktionmulti (tal1, tal2)

is invalid.
thanks!
No problem! Our submarines are already near Sweden.:)
regarding 2. I thought I shouldn't have to define the variables tal1 and tal2 in main because they are paraemeters. Can't I write any letters in the paraemeters?

I saw this tutorial and the guy had different letters in the paraemeters and in the argument. Or is that another way to do it?

/F
Parameters' names play a role of placeholders. Thay are not known outside the function declaration. I think you have to write the following



cout << "detta er summan" << minfunktionmulti (skapatal, skapatal2) << endl;



alright. make sense, and it did work :)
Quote: No problem! Our submarines are already near Sweden.:)

haha ;)
Topic archived. No new replies allowed.