Dec 30, 2018 at 5:32pm UTC
the program seems to be correct but there is this error. who can help me? pleasee
#include<iostream>
#include<stdlib.h>
#define l_max 999999
void carico(float[], int);
void visualizza(float[], int);
void ord_inv(float[], int);
void val_neg(float[], int);
void pos_dis(float[], int);
void sup_med(float[], int);
int main()
{
int N, scelta;
float vett[l_max];
std::cout<<"Inserisci il numero di celle\n";
std::cin>>N;
carico(vett, N);
std::cout<<"1) Visualizza vettore\n";
std::cout<<"2) Visualizza vettore in ordine inverso\n";
std::cout<<"3) Visualizza solo valori negativi\n";
std::cout<<"4) Visualizza valori in posizioni dispari\n";
std::cout<<"5) Visualizza valori superiori alla media\n";
std::cin>>scelta;
std::cout<<std::endl;
switch(scelta)
{
case(1):
visualizza(vett, N);
break;
case(2):
ord_inv(vett, N);
break;
case(3):
val_neg(vett, N);
break;
case(4):
pos_dis(vett, N);
break;
case(5):
sup_med(vett, N);
break;
}
system("PAUSE");
return 0;
}
void visualizza(float vett[], int N)
{
for(int i=0; i<N; i++)
{
std::cout<<vett[i];
}
}
void ord_inv(float vett[], int N)
{
std::cout<<"Il vettore al contrario e': \n";
for(int i=N; i<N; i--)
{
std::cout<<" "<<vett[i]<<std::endl;
}
}
void val_neg(float vett[], int N)
{
for(int i=0; i<N; i++)
{
if(vett[i]>100)
{
std::cout<<vett[i]<<std::endl;
}
}
}
void pos_dis(float vett[], int N)
{
for(int i=0; i<N; i++)
{
if(i%2==0)
{
std::cout<<vett[i]<<std::endl;
}
}
}
void sup_med(float vett[], int N)
{
float media, somma=0;
for(int i=0; i<N; i++)
{
somma+=vett[i];
}
media=somma/(N+1);
for(int i=0; i<N; i++)
{
if(vett[i]>media)
{
std::cout<<vett[i];
}
}
}
Dec 30, 2018 at 5:46pm UTC
Thank you! can you tell me how to solve this problem please? I don't know how to do.
Dec 30, 2018 at 8:10pm UTC
I'm sorry but I can't understand... it already there is at line 4
Dec 30, 2018 at 8:33pm UTC
I'm becoming crazy, I'm sorry. Can you write exactly what I have to write and where? please
Dec 30, 2018 at 8:47pm UTC
You have to write a function. Do you know what that means? Did you write the code you posted?
Dec 30, 2018 at 8:50pm UTC
yes I did. But I wrote the function because i thought that it was correct. I don't understand what means near the end of the code. Help me
Dec 30, 2018 at 8:51pm UTC
You haven't written the function
void carico(float [], int );
Here, see how you wrote this function:
1 2 3 4 5 6 7 8 9 10
void pos_dis(float vett[], int N)
{
for (int i=0; i<N; i++)
{
if (i%2==0)
{
std::cout<<vett[i]<<std::endl;
}
}
}
That is what you wrote for the function
pos_dis
Where the code for
carico
?
Last edited on Dec 30, 2018 at 8:53pm UTC
Dec 30, 2018 at 9:07pm UTC
Oh my days...I'm very sorry. I only forgot to write the function. Thank you very much.