Thread: Arrays

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    34

    Arrays

    What up gang, Hay this is The Ski calling out to all you helpful and fine programmers out there in Wonderland, and my wonder of the night is what am I doing wrong with the arrays? I do pay attention in class but sometimes when you are in a class of 100 people sometimes you can get your questions answered and sometimes you cannot due to time contraints. But hay why worry when I have all you GREAT people to help me out. Anyways:
    Enough of the jive talk from me. Here is a program I am working on and below that is my compiling errors. What am I doing wrong that the system will not let me compile the program?


    //
    //
    //
    //
    // Nov 6, 2001
    // This program is used to catigorize salary and commission to the a range of a payscale.

    #include <iostream.h>
    #include <iomanip.h>

    const int arsize1 = 50;
    const int arsize2 = 5;

    using std::cout;
    using std::cin;
    using std::endl;

    int main()
    {

    int num1[arsize1], num2[arsize2], num3[arsize1],num4[arsize1];
    num1[arsize1] = 0;
    num2[arsize2] = 0;
    num3[arsize1] = 0;
    num4[arsize1] = 0;

    cout << "Please enter the gross sales amount (-1 to end):";
    cin >> num1[0];

    while ( num1[arsize1] != -1 )
    {
    for (int count1 = 0; count1 < arsize1; count1++ )
    {
    num3[count1] = num1[count1] * .09;
    num4[count1] = num3[count1] + 200;
    cout <<"The salary for that sales amount is: " << num4[count1] << endl;
    if ( num4[count1] <= 399 )
    num2[1] = num2[1] + 1;
    else if (( num4[count1]>= 400) && (num4[count1] <= 599 )
    num2[2] = num2[2] + 1;
    else if (( num4[count1]>= 600) && (num4[count1] <= 799 )
    num2[3] = num2[3] + 1;
    else if (( num4[count1]>= 800) && (num4[count1] <= 999 )
    num2[4] = num2[4] + 1;
    else if ( num4[count1]>= 400)
    num2[5] = num2[5] + 1;
    }

    }
    cout << endl;
    cout << "RESULTS!" << endl;
    cout << endl;
    cout << num2[1] << " people fell into the range of 200 to 399" << endl;
    cout << num2[2] << " people fell into the range of 400 to 599" << endl;
    cout << num2[3] << " people fell into the range of 600 to 799" << endl;
    cout << num2[4] << " people fell into the range of 800 to 999" << endl;
    cout << num2[5] << " people fell into the range of 1000 and up" << endl;
    return 0;
    }


    ERRORS:
    prog_19.cpp: In function `int main()':
    prog_19.cpp:34: warning: assignment to `int' from `double'
    prog_19.cpp:40: parse error before `['
    prog_19.cpp:59: confused by earlier errors, bailing out

    Now the one error I think I may know because I am dealing with multiply by .09. Do I have to include the math library? And what do I have to do to avoid outputting a double variable, just keeping it as a regular integer?
    http://members.ebay.com/aboutme/the_ski/

  2. #2
    William
    Guest
    You are missing a few ')'.

    Here's you error :

    else if (( num4[count1]>= 400) && (num4[count1] <= 599 )
    num2[2] = num2[2] + 1;
    else if (( num4[count1]>= 600) && (num4[count1] <= 799 )
    num2[3] = num2[3] + 1;
    else if (( num4[count1]>= 800) && (num4[count1] <= 999 )
    num2[4] = num2[4] + 1;

    Should be :

    else if (( num4[count1]>= 400) && (num4[count1] <= 599 ))
    num2[2] = num2[2] + 1;
    else if (( num4[count1]>= 600) && (num4[count1] <= 799 ))
    num2[3] = num2[3] + 1;
    else if (( num4[count1]>= 800) && (num4[count1] <= 999 ))
    num2[4] = num2[4] + 1;

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Thank You!!!!!!!!!!
    http://members.ebay.com/aboutme/the_ski/

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Ok corrected the obvious "Ski is Blind errors" But now my little problem is the assignment of int to double error. When multiplying integer to a double, promotion should take place or am I doing it in a wrong manner?
    http://members.ebay.com/aboutme/the_ski/

  5. #5
    William
    Guest
    It's just a warning (at least that's what's written!!!)
    you have
    int=int*double;
    int*double gives a double, so you have
    int=double;

    the compilers warns you that you are converting a double to an int. To avoid this warning you could cast :
    int=(int)double;

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    ok so as far as code written, how do you correct that and stop the program from running like a rapped ape when I execute it?
    http://members.ebay.com/aboutme/the_ski/

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    err as already said use a cast. Or make sure that the result is stored in a double and not an int. The second way causes no loss of data.The first causes a loss of data but because you explicitly cast to an int your compiler will probably not complain.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM