Thread: no match for 'operator<=' in 'qual1

  1. #31
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    that how i had it , and it works kindof
    i think that is all that matters when coding

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's far cry from what you had.
    And you are dead wrong if all you think that matters is working.
    Readability is first and foremost important.
    And second is semantically correct, not just something that "works" (it shall not be undefined behavior).

    If you fail to follow these principles, then you will become another esbo. A pitiful programmer who is full of bad practices and creates poor, unmaintainable code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    you cant just make up names. that's unfair
    i want to make a name now.

    but really my if statements
    Code:
    if (qual[0]<=150)
    if (qual[1]<=250)
    if (qual[2]<=115)
    if (qual[3]<=435)
    if (qual[4]<=250)
    they are not right are they.

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I didn't make the name up.
    And yes, that works, if you initialize those variables with something first.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #35
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    like this
    Code:
    float qual[4];

  6. #36
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by rfoor View Post
    like this
    Code:
    float qual[4];
    That (a) initializes nothing at all and (b) makes sure you don't have an element called "qual[4]". If you need an element called "qual[4]", then you need to have five elements total, which means you need to declare your array to have five elements.

    (Edit: And presumably, in your actual program, you wouldn't initialize these elements, so much as read them in from the user.)

  7. #37
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    if (qual[0]<=150.0f)
    if (qual[1]<=250.0f)
    if (qual[2]<=115.0f)
    if (qual[3]<=435.0f)
    And what you posted is the definition of the array, not the initialization.
    The variables must be assigned some value before you test them. If you do that, then yes, it works.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #38
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    so to initialize them i would go

    part[0]=part1
    part[1]=part2

    because im reading the quality from a txt file and im going to use it in my statement saying that you have to reorder something.

  9. #39
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    By reading, you are assigning something, yes?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #40
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    idk i just want it to read it and if it is less print out that part number along with a total .
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    float total;
    char part[4];
    float qual[4];
    float cost[5];
    
    int main(){
        ifstream file;
      
          file.open("Part.txt");
          
      
    if (qual[0]<=150){
                      cout<<"Reorder 200 of part "<<part[0]<<endl;
                                     total=cost[0]*200;
                                          cout<<"Total reorder cost:$"<<total<<endl;}
                                          
    if (qual[1]<=250){
                      cout<<"Reorder 300 of part "<<part[1]<<endl;
                                     total=cost[1]*300;
                                     cout<<"Total reorder cost:$"<<total<<endl;}
                                     
    if (qual[2]<=115){ 
                       cout<<"Reorder 150 of part "<<part[2]<<endl;
                                      total=cost[2]*150;
                                      cout<<"Total reorder cost:$"<<total<<endl;}
                        
    if (qual[3]<=435){
                      cout<<"Reorder 500 of part "<<part[3]<<endl;
                                     total=cost[3]*500;
                                     cout<<"Total reorder cost:$"<<total<<endl;}
                      
    if (qual[4]<=250){
                      cout<<"Reorder 750 of part "<<part[4]<<endl;
                                     total=cost[4]*750;
                                     cout<<"Total reorder cost:$"<<total<<endl;}
    
          
                   
     file.close();
    
    
    
    system("pause");
    return 0;
    }
    or do you think i should let the other program use the if statement and print it out on the txt file and then i just read that(assuming it prints to the txt file meeting the requirments).
    Last edited by rfoor; 02-13-2009 at 09:48 AM.

  11. #41
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, let's keep that out of the file.
    So read in the data and make it work.
    But first, you still haven't fixed the indentation.
    And another problem is that you are comparing a float to an integer:
    if (qual[3]<=435)
    A floating point number is represented with the addition of .0f, so it should be:
    if (qual[3]<=435.0f)
    Last edited by Elysia; 02-13-2009 at 10:13 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #42
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Your current code doesn't read anything from the file...

    AND for the 5th time from me alon: This is using an element that doesn't exist in qual array:

    Code:
    if (qual[4]<=250){
                      cout<<"Reorder 750 of part "<<part[4]<<endl;
                                     total=cost[4]*750;
                                     cout<<"Total reorder cost:$"<<total<<endl;}
    I would also suggest that you put the end-brace on the line after cout, rather than at the end of that line - it makes it much easier to "find" when you are scanning through the code.

    --
    Mats
    Last edited by matsp; 02-13-2009 at 09:58 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #43
    Registered User QuestionKing's Avatar
    Join Date
    Jan 2009
    Posts
    68
    Maybe what you need is an overall clear picture of how the array numbering system works:

    Code:
    int MySampleArray[4];
    This does not give you index #4. It gives you 4 indices total. Which are numbered 0, 1, 2, and 3.
    ...and
    Code:
    file.open
    does not read any content of a file no more than double clicking a .txt file on your desktop would make you learn the contents. It simply opens it. You have to read it if you want to know what is in it, AFTER you open it. Read This

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-30-2009, 06:37 PM
  2. no match for 'operator>>'
    By Taka in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2009, 12:17 AM
  3. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  4. 2 array match
    By ajastru2000 in forum C++ Programming
    Replies: 5
    Last Post: 07-18-2003, 07:58 AM
  5. How do I match 2 files to print data.
    By sketchit in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-12-2001, 05:45 PM