Array

Pages: 12
I tried the 3rd function and added it into my programm:

#include <iostream>
#include <iomanip>


using namespace std;

double output(double array[], int);
double input(double array[], int max, int n) {
for (int i = 0; i < (n - 1); i ++) {
std::cout << "Please enter a decimal for value " << i + 1 << ": ";
std::cin >> array[i];
}
return 0; // Not sure why the function is supposed to return a double
}

int main()
{
char auswahl;
int anzahl;
const int index=20;
double inputRAY[index];

cout << "Hi was geht ab\n"
<< "ich steh auf dummy texte.\n"
<< "A. Arraygroesse festlegen(folgt B).\n"
<< "B. Array eingabe.\n"
<< "C. Gib ma was aus.\n"
<< "D. Kopieren.\n"
<< "E. Mischen.\n";
cin >> auswahl;

switch (auswahl)
{
case 'a':
case 'A':
cout << "Wie groß soll dein Array sein?\n";
cin >> anzahl;

case 'B':
case 'b':
input(inputRAY,index,anzahl);
cout << "eingabe abgeschlossen\n\n";
cin.get();
break;

case 'C':
case 'c':
cout << "Dein Array soll ausgegeben werden? ...\n";
output(inputRAY, anzahl);
cout << "Zufrieden ??\n";

case 'D':
case 'd':

using std::end;
using std::begin;

std::vector<int> a{1,4,6,8,2,9},
b{1,0,2,3,4,5,6};


std::copy( begin(a)+1, begin(a)+3+1, begin(a)+2 ); // Das +1 bei Ende, weil [Anfang,Ende)

std::copy( begin(b), end(b), std::ostream_iterator<int>(std::cout, ", "));

case 'E':
case 'e':



}

return (0);
}







double output(double inputRAY[],int anzahl)
{
for (int zaehler=0; zaehler<anzahl; zaehler++)
{
cout << "Was geht ab digga an der stelle " << zaehler << endl
<< "im Array befindet sich die " << zaehler+1 << ". Zahl nämlich die:" <<endl
<< inputRAY[zaehler]<< endl << endl;
}
return (0);
}

But its showing an error on using std.

Why?
Has somebody an idea why it´s showing an error?
I don't know why all of a sudden you omit the code tags. Put the code in code tags and tell the line number where the error occurs and tell the error itself.

What I see is that in case 'd' you define local variables. You need curly brace to do that. beginning after the case until or up to the break

Don't forget the break
Last edited on
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
#include <iostream>
#include <iomanip>


using namespace std;

double output(double array[], int);
double input(double array[], int max, int n) {
for (int i = 0; i < (n - 1); i ++) {
std::cout << "Please enter a decimal for value " << i + 1 << ": ";
std::cin >> array[i];
}
return 0; // Not sure why the function is supposed to return a double
}

int main()
{
char auswahl;
int anzahl;
const int index=20;
double inputRAY[index];

cout << "Hi was geht ab\n"
<< "ich steh auf dummy texte.\n"
<< "A. Arraygroesse festlegen(folgt B).\n"
<< "B. Array eingabe.\n"
<< "C. Gib ma was aus.\n"
<< "D. Kopieren.\n"
<< "E. Mischen.\n";
cin >> auswahl;

switch (auswahl)
{
case 'a':
case 'A':
cout << "Wie groß soll dein Array sein?\n";
cin >> anzahl;

case 'B':
case 'b':
input(inputRAY,index,anzahl);
cout << "eingabe abgeschlossen\n\n";
cin.get();
break;

case 'C':
case 'c':
cout << "Dein Array soll ausgegeben werden? ...\n";
output(inputRAY, anzahl);
cout << "Zufrieden ??\n";

case 'D':
case 'd':

using std::end;   //  error
using std::begin; // error

std::vector<int> a{1,4,6,8,2,9},
b{1,0,2,3,4,5,6};


std::copy( begin(a)+1, begin(a)+3+1, begin(a)+2 ); // Das +1 bei Ende, weil [Anfang,Ende)

std::copy( begin(b), end(b), std::ostream_iterator<int>(std::cout, ", "));

case 'E':
case 'e': 



}

return (0);
}



the eroor is std end has benn not declared,

vector is not a member of std
in order to use end()/begin() you need to #include <iterator> (you know that's C++11, don't you?).

You don't need the using expressions.
using namespace std; does already kind of remove the std:: for the laziness...

[EDIT]
Are you sure you know what copy does? See:

http://www.cplusplus.com/reference/algorithm/copy/
Last edited on
Can you tell me perhaps a better way to do it.?
Can you tell me perhaps a better way to do it.?
what?
Tazzy is either a troll, or someone who doesn't want to learn the language and just wants the answers. The function I created was just copy pasted, the vector code was copy pasted, and they keep asking for all of the functions to be written for them (in one form or another). They've also been asked several times to use code tags and keep neglecting them.

They also refuse to take time to learn how to code, and constantly post looking for "help" when things don't go well.

@Tazzy
This isn't an easy program to do, but you should already know how to do everything the homework is asking for. I'm sorry if you didn't want to take this class but were required to, but that doesn't mean we're just going to write your homework for you, there are websites for that.

What I will offer is providing you links so that you can learn and make an attempt to integrate your knowledge into your program. I will also help you correct any of your code that you're struggling with, but not all of it. I will also help you fix any errors you run into provided you supply the actual error and the code in question.

I understand that you're already struggling with one language barrier, and struggling with that plus programming is incredibly hard. My only suggestion is that you talk to your teacher and see if they can get someone to explain it to you better in your native language.
Topic archived. No new replies allowed.
Pages: 12