#My programing teacher gave me a homework task wich i kind of find it dificult

48 messages · Page 1 of 1 (latest)

austere totem
#

We didnt do much C++ because its my first year yet he expects for us to make a full code to sort positive , negative , par and impar variables
heres my code so far
#include <iostream>
using namespace std;

int list[50];
int tab[10] ={3, 6, 9, 1, 4, 7, 8, -8, -69, -45},n = 10, i;
void InputData(int n)
{
int i;

for(i=0; i < n; i++){
    cout<<"["<<i+1<<"]: ";
    cin>>list[i];
  }  

}

void SortData(int n)
{
cout <<"pare =";
for(i=0; i < n; i++) {
cout << tab[i];
if(i<n-1)
cout << ",";
}
cout>>endl
}

cout <<"impare =";
for(i =0; i < n; i++);
if (tab[i] % 2 !=0){
    cout << ",";
cout<<endl;

cout<<"pozitive =";
for (int i =0; i < n; i++)
if (tab[i] > 0)
   cout << tab[i] << ","
cout<<endl 

}

void ShowData(int n)
{
int i;
for(i=0; i<n; i++)
cout<<list[i]<<endl;

 }

int main(void)
{
int n;
cout <<"quantity of numbers: ";
cin>>n;

// define needed variables
InputData(n);

//sort data input
SortData(n);

//show sort data
ShowData(n);


return 0;

}     

yet i dont know how to make it work

rare questBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

broken whale
#
#include <iostream>
using namespace std;

int list[50];
int tab[10] ={3, 6, 9, 1, 4, 7, 8, -8, -69, -45},n = 10, i;
void InputData(int n)
{
   int i;

    for(i=0; i < n; i++){
        cout<<"["<<i+1<<"]: ";
        cin>>list[i];
      }



}

void SortData(int n)
{
    cout <<"pare =";
    for(i=0; i < n; i++) {
        cout << tab[i];
        if(i<n-1)
         cout << ",";
      }
     cout>>endl
     }


    cout <<"impare =";
    for(i =0; i < n; i++);
    if (tab[i] % 2 !=0){
        cout << ",";
    cout<<endl;

    cout<<"pozitive =";
    for (int i =0; i < n; i++)
    if (tab[i] > 0)
       cout << tab[i] << ","
    cout<<endl 
 }
 
 void ShowData(int n)
 {
    int i;
    for(i=0; i<n; i++)
       cout<<list[i]<<endl;

     }

int main(void)
{
    int n;
    cout <<"quantity of numbers: ";
    cin>>n;

    // define needed variables
    InputData(n);

    //sort data input
    SortData(n);

    //show sort data
    ShowData(n);


    return 0;

    }
austere totem
#

oh

#

ty

broken whale
#

do ```

#

grave key

#

not '

#

next to 1

austere totem
#

oh i see

broken whale
#

what is ur prof asking for

#

whats wrong

austere totem
#

he asked for us to make the program sort variables

#

in 4 category

#

positive , negative

#

then even and odd

#

we did only theory before

#

without normal explanation

#

he told us to use geany

#

also geany gives me error 9009 even tho i did his setup with the Tdm

#

@broken whale got any ideas how i can fix my code?

broken whale
#

idk what it even does

austere totem
#

lol

#

well ty anyways

rare questBOT
#

@austere totem Has your question been resolved? If so, type !solved :)

loud iron
#

You have a couple of things wrong in sortData function.

  • sortData usually means you’re going to sort it in ascending or descending order, so you might want to think of a better function name.
  • if the value is odd you just print a comma instead of the value in impare part.
  • cout >> endl; will cause an error. Pay attention to the direction they’re facing.
#

Do you know how to calculate whether a number is even or odd?

austere totem
#

I am a highschool student and we didnt have a teach for the past 2 years where we were supposed to learn to code but this is my last year and they found a teacher , and he comes from a codding college and he thinks we know everything. Coding in my school is a subject like math , english , biology and more

loud iron
#

That’s really unlucky. They’re forcing you to learn the basics and more quickly due to their problems

austere totem
#

ok ty

#

so ig i will type solved now?

#

it really didnt solve it but idk

#

i think ill just tell him how things are

loud iron
#

If you ask specific questions, it’s easier to answer.

#

Like are you having trouble with printing only the even or odd numbers, figuring out how arrays work, or something else

rare questBOT
#

@austere totem Has your question been resolved? If so, type !solved :)

whole hamlet
#

why dont you start by writing out what you want your program to do step by step, in detail, without any c++ syntax. Its easier if you have a clear vision of how you want your program to work

austere totem
#

So my program should start with asking me how many variables should i add like if i press 5 then i will have to add 5 numbers , then after i add the numbers , for example 4, 3, 6 ,-8, -9 the program should sort my numbers by creating 4 different categorys:
a)positive: 3, 4,6
b)negative:-8,-9
c)odd: 3,-9
d)even: 4,6,-8

austere totem
#

My programing teacher gave me a homework task wich i kind of find it dificult

whole hamlet
#

dont try to do everything all at once

#

im going to bed now so i wont be responding to any pings until tomorrow

austere totem
#

thanks but the thing is i have to show it tmrow so ill just give up rn cuz its not posible for me

rare questBOT
#

@austere totem Has your question been resolved? If so, type !solved :)