what's the problem?
E:\Tools\Programming\C++ Programming\CodeBlocks\Project\Knowledge_Based_Project\Exercise_Temporary_Compiler\Exercise_Temporary_3\main.cpp||In function 'int main()':|
E:\Tools\Programming\C++ Programming\CodeBlocks\Project\Knowledge_Based_Project\Exercise_Temporary_Compiler\Exercise_Temporary_3\main.cpp|36|error: invalid use of member (did you forget the '&' ?)|
||=== Build finished: 1 errors, 0 warnings ===|

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    // informed user
    cout << "Please insert several amount of number: /n";

    // input
    int inputs;
    vector<int> numstore;

    while (cin >> inputs)
        numstore.push_back(inputs);


    // re-arrange element in vector.
    sort(numstore.begin(), numstore.end());

    // formed a loop that iterate through each ele in (numstore)
    const int quadro = 4;
    int quartiles = 1;
    vector<double> quaele;

    for (vector<int>::size_type counter = 0; (quartiles == quadro) || (counter < numstore.size()); ++counter)
        if (counter == (quartiles/quadro * numstore.size()))
        {
            quaele.push_back(numstore[counter]);
            if ((quartiles == 2) && (numstore.size / 2 == 0))
                quaele[quartiles-1] = (numstore[counter]+numstore[counter-1]) / 2;
            ++quartiles;
        }


    // outputting
    streamsize prec = cout.precision();
    cout << "Your final grade is: /n" << setprecision(3);

    for (vector<double>::size_type counter = 0; counter < quaele.size(); ++counter)
        cout << quaele[counter] << "/n";

    cout << setprecision(prec) << endl;

    // success indicator
    return 0;
}

Recommended Answers

All 5 Replies

numstore.size is a function, not a member. Add the () to get it to compile. And change /n to \n.

// Error
if ((quartiles == 2) && (numstore.size / 2 == 0))
// Fixed
if ((quartiles == 2) && (numstore.size() / 2 == 0))

great, thnx, btw, on line 31 why does even counter == 0, the conditional if execute?

*no attachment*

just try to compile the program and see the result...

Not completely sure what you are asking.
The if executes because if you entered data on line 19 the check

(quartiles == quadro) || (counter < numstore.size())

is true. First part is false but second part is true. So, (false || true) = true
Is that what you were asking?

no,

I'm talking about the conditional in if not the for loop

i mean on the first loop, counter == 0

so, how can counter == 1(quartiles) / 4(quadro) * 10(element number), this is what I input

0 1 2 3 4 5 6 7 8 9

but then, it output

0

this is so weird, I mean the it will take the number in first element, and then the if condition continue to be false and that's what all it get, so how can counter == 0 == 1/4 * 10?

Because of integer divide. 1/4 is 0.25 but 0.25 as an integer is 0.
Hence, count == 0 == quartiles/quadro * 10(element number) == 0 * 10*size.
Once you cast one of them to a float or a double you get the result of 0.25.
Check out this code to see what I mean.

#include <iostream>
int main(){
  int quadro(4),quartiles(1);
  std::cout << "quartiles/quadro        = " << quartiles/quadro << std::endl;
  std::cout << "float(quartiles)/quadro = " << float(quartiles)/quadro << std::endl;
  std::cout << "quartiles/float(quadro) = " << quartiles/float(quadro) << std::endl;
  std::cout << "float(quartiles/quadro) = " << float(quartiles/quadro) << std::endl;
  return 0;
}
quartiles/quadro        = 0
float(quartiles)/quadro = 0.25
quartiles/float(quadro) = 0.25
float(quartiles/quadro) = 0

Also, the value of quartiles/quadro * numstore.size() must be a integer to be able to checks it's value with counter, because counter is an integer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.