Mar 10, 2014 at 6:40pm UTC
Hello!
Please, is the first function ok indentated now? The problem is I saw many different types and I even don't know which of them are right and which not, so I am not able to learn from them...
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 75 76 77 78 79 80 81 82
#include<iostream>
using namespace std;
int new_int(int a){
cin>>a;
return a;
}
int * f2(int z)
{
int * str=new int [40];
int s=-1;
srand(time(0));
int zn=0;
int random_integer;
for (int index=0; index<10; index++){
random_integer = (rand()%(z));
str[index]= random_integer;
cout<<"str[" <<index<<"]=" <<random_integer<<endl;
s=s+1;
zn=zn+random_integer;
if (zn>3*z){
cout<<"Last value is: " <<random_integer<<endl<<
"Whole sum is: " <<zn<<endl<<"Index number: " <<s;
break ;
}
}
return str;
delete []str;
}
void sort(int po[40], int do2)
{
for (int p=1; p < do2; p++) {
for (int i=0; i < do2-p; i++) {
if (po[i] < po[i+1]) {
int temp = po[i];
po[i] = po[i+1];
po[i+1] = temp;
}
}
}
for (int t=0;t<do2;t++){
cout<<po[t]<<endl;}
}
int add(int po[40], int do3)
{
int all=0;
for (int z=0;z<do3;z++){
all=all+po[z];
}
return all;
}
int main()
{
int amain;
int doh=new_int(amain);
int tre=doh/3;
int vp=40;
int * z;
z=f2(tre);
cout<<endl<<endl<<endl;
// for(int h=0;h<40; h++) {cout<<z[h]<<endl;}
sort(z, vp);
cout<<"The whole sum: " <<add(z, vp)<<endl;
delete []z;
return 0;
}
Last edited on Mar 10, 2014 at 6:53pm UTC
Mar 10, 2014 at 6:46pm UTC
Yes, that looks sensible to me.
There are various different styles you can use, and it's not too important which one you choose, as long as it's a sensible one and you're consistent in using it.
Doesn't your C++ textbook suggest an indentation style you can use?
Mar 10, 2014 at 6:54pm UTC
Thanks, MikeBoy!:)
Better now ( I "tidied" it a little!)
What is the first mistake now?