I don't know what's wrong with this code, I'm a c++ newbie, could someone help me fix it? I've been having issues with this for some time and I don't know how to fix it. I've tried messing with the code, but to no success. Anyone know what's wrong with this?
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <list>
using namespace std;
void rising(double T[], int n)
{
double pom;
for (int j=n-1;j>0;j--)
for (int i=0;i<j;i++)
if (T[i]>T[i+1])
{
pom=T[i];
T[i]=T[i+1];
T[i+1]=pom;
}
}
void lowering(double T[], int n)
{
double pom;
for (int j=n-1;j>0;j--)
for (int i=0;i<j;i++)
if (T[i]<T[i+1])
{
pom=T[i];
T[i]=T[i+1];
T[i+1]=pom;
}
}
void show(double T[], int n)
{
for(int i=0; i<n; i++)
cout<<T[i]<<setw(3);
cout<<endl;
}
int main()
{
double tablica[]={2, 12, 3, 4, 5, 4, 7, 8, 9, 9, 0};
cout<<"elementy tablicy to: "<<show(tablica,11)<<endl;
cout<<"elementy tablicy posortowane rosnaco: "<<rising(tablica,11)<<endl;
cout<<"elementy tablicy posortowane malejaco: "<<lowering(tablica,11)<<endl;
cin.get();
cin.ignore();
return 0;
}
The problem is here:
cout<<"elementy tablicy to: "<<show(tablica,11)<<endl;
<<show(tablica,11)
to function show does not return any value (its return type is void),
you can simply call the function to perform its print:
int main()
{
double tablica[] = { 2, 12, 3, 4, 5, 4, 7, 8, 9, 9, 0 };
cout << "elementy tablicy to: ";
show(tablica, 11);
Your functions have void return type, there is nothing <<
operator can do with them, fortunately you already have the functions to do what you want, you just have to call them in the correct fashion and order:
int main()
{
double tablica[]={2, 12, 3, 4, 5, 4, 7, 8, 9, 9, 0};
cout<<"elementy tablicy to: ";
show(tablica,11);
rising(tablica,11);
cout<<"elementy tablicy posortowane rosnaco: ";
show(tablica,11);
lowering(tablica,11);
cout<<"elementy tablicy posortowane malejaco: ";
show(tablica,11);
cin.get();
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.