no match for 'operator<=' in 'qual1

This is a discussion on no match for 'operator<=' in 'qual1 within the C++ Programming forums, part of the General Programming Boards category; hi i am making a program where you enter the data with one program and if the values are less ...

  1. #1
    new to c++
    Join Date
    Feb 2009
    Posts
    53

    no match for 'operator<=' in 'qual1

    hi i am making a program where you enter the data with one program and if the values are less than a number it will tell you to reorder so many more it then goes into a txt file and then i want to have another file read specific lines from that txt file like if the values are less it then writes it to a file(the ones i want) plus if i do reorder the parts i want to know the total. using Dev C++ Thanks a bunch

    input file:
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    
    string Part1;
    string Part2;
    string Part3;
    string Part4;
    string Part5;
    string des1;
    string des2;
    string des3;
    string des4;
    string des5;
    float qual1;
    float qual2;
    float qual3;
    float qual4;
    float qual5;
    float order1;
    float order2;
    float order3;
    float order4;
    float order5;
    float quan1;
    float quan2;
    float quan3;
    float quan4;
    float quan5;
    float cost1;
    float cost2;
    float cost3;
    float cost4;
    float cost5;
    float  total1;
    float  total2;
    float  total3;
    float  total4;
    float  total5;
    
    int main(){
        fstream file("Part.txt",ios::out);
        
        
        cout<<"Part Number: ";
        cin>>Part1;
        file<<Part1<<endl;
        
        cout<<"Part Description: ";
        cin>>des1;
        file<<des1<<endl;
        
        cout<<"Quality on Hand: ";
        cin>>qual1;
        file<<qual1<<endl;
    
        cout<<"Unit Cost: ";
        cin>>cost1;
        file<<cost1<<endl;
        
        
        cout<<"Part Number: ";
        cin>>Part2;
        file<<Part2<<endl;
        
        cout<<"Part Description: ";
        cin>>des2;
        file<<des2<<endl;
        
        cout<<"Quality on Hand: ";
        cin>>qual2;
        file<<qual2<<endl;
        
        cout<<"Unit Cost: ";
        cin>>cost2;
        file<<cost2<<endl;
        
        
        cout<<"Part Number: ";
        cin>>Part3;
        file<<Part3<<endl;
        
        cout<<"Part Description: ";
        cin>>des3;
        file<<des3<<endl;
        
        cout<<"Quality on Hand: ";
        cin>>qual3;
        file<<qual3<<endl;
        
        cout<<"Unit Cost: ";
        cin>>cost3;
        file<<cost3<<endl;
        
        
        cout<<"Part Number: ";
        cin>>Part4;
        file<<Part4<<endl;
        
        cout<<"Part Description: ";
        cin>>des4;
        file<<des4<<endl;
        
        cout<<"Quality on Hand: ";
        cin>>qual4;
        file<<qual4<<endl;
        
        cout<<"Unit Cost: ";
        cin>>cost4;
        file<<cost4<<endl;
        
        
        cout<<"Part Number: ";
        cin>>Part5;
        file<<Part5<<endl;
        
        cout<<"Part Description: ";
        cin>>des5;
        file<<des5<<endl;
        
        cout<<"Quality on Hand: ";
        cin>>qual5;
        file<<qual5<<endl;
        
        cout<<"Unit Cost: ";
        cin>>cost5;
        file<<cost5<<endl;
        
        if (qual1<=150){total1=cost1*200;
                        file<<"Reorder 200 of Part number xl101 now!"<<endl;
                        file<<Part1<<" total reorder cost: $"<<total1<<endl;}
        if (qual2<=250){total2=cost2*300;
                        file<<"Reorder 300 of Part Number xm215 now!"<<endl;
                        file<<Part2<<" total reorder cost: $"<<total2<<endl;}
        if (qual3<=115){total3=cost3*150;
                        file<<"Reorder 150 of Part Number xr218 now!"<<endl;
                        file<<Part3<<" total reorder cost: $"<<total3<<endl;}
        if (qual4<=435){total4=cost4*500;
                        file<<"Reorder 500 of Part Number xg321 now!"<<endl;
                        file<<Part4<<" total reorder cost: $"<<total4<<endl;}
        if (qual5<=250){total5=cost5*750;
                        file<<"Reorder 750 of Part Number xk178 now!"<<endl;
                        file<<Part5<<" total reorder cost: $"<<total5<<endl;}
    file.close();
    system("pause");
    return 0;
    }

    and here is the file that reads it. (file that has the errors on it)
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    
    string Part1;
    string Part2;
    string Part3;
    string Part4;
    string Part5;
    float qual1;
    float qual2;
    float qual3;
    float qual4;
    float qual5;
    float cost1;
    float cost2;
    float cost3;
    float cost4;
    float cost5;
    float total1;
    float total2;
    float total3;
    float total4;
    float total5;
    
    
    int main(){
        ifstream file;
        string qual1;
        string qual2;
        string qual3;
        string qual4;
        string qual5;
        string cost1;
        string cost2;
        string cost3;
        string cost4;
        string cost5;
        string total1;
        string total2;
        string total3;
        string total4;
        string total5;
          file.open("Part.txt");
          
          getline(file,Part1);
          getline(file,Part2);
          getline(file,Part3);
          getline(file,Part4);
          getline(file,Part5);
          getline(file,qual1);
          getline(file,qual2);
          getline(file,qual3);
          getline(file,qual4);
          getline(file,qual5);
          getline(file,cost1);
          getline(file,cost2);
          getline(file,cost3);
          getline(file,cost4);
          getline(file,cost5);
          getline(file,total1);
          getline(file,total2);
          getline(file,total3);
          getline(file,total4);
          getline(file,total5);
          
          
          
        if (qual1<=150){total1=cost1*200;
                        cout<<"Reorder 200 of Part number:"<<Part1<<" now!"<<endl;
                        cout<<Part1<<" total reorder cost: $"<<total1<<endl;}
        if (qual2<=250){total2=cost2*300;
                        cout<<"Reorder 300 of Part Number:"<<Part2<<" now!"<<endl;
                        cout<<Part2<<" total reorder cost: $"<<total2<<endl;}
        if (qual3<=115){total3=cost3*150;
                        cout<<"Reorder 150 of Part Number:"<<Part3<<" now!"<<endl;
                        cout<<Part3<<" total reorder cost: $"<<total3<<endl;}
        if (qual4<=435){total4=cost4*500;
                        cout<<"Reorder 500 of Part Number:"<<Part4<<" now!"<<endl;
                        cout<<Part4<<" total reorder cost: $"<<total4<<endl;}
        if (qual5<=250){total5=cost5*750;
                        cout<<"Reorder 750 of Part Number:"<<Part5<<" now!"<<endl;
                        cout<<Part5<<" total reorder cost: $"<<total5<<endl;}               
     file.close();
    system("pause");
    return 0;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In the second piece you are trying to compare qual1 with the value 150. Since qual1 is a string, not a number, the compiler says "Huh? You are trying to compare a string with an integer value" - unfortunately, it's not quite as straightforward in saying it as I am, because it doesn't really understand what a std::string is - just that there is no direct way of making it into an integer, and that there is no compare function declared for "string and integer".

    --
    Mats
    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.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Also, whenever you have a temptation to put numbers onto variable names you should be using arrays and loops instead (that is, you could do with 7 variables - arrays - instead of 35 variables). And variables should be declared inside functions, otherwise they are global for which there is absolutely no reason if your program consists of only one function in the first place (and little reason in other cases as well).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    some horrendous code
    That's not how to program. You'd be doing yourself a huge favour by selecting most of that code and pressing the delete key. You don't implement more than one of something by using multiple variables, you use an array. Don't try writing this program without learning how to use arrays.
    There are tutorials on thie site I believe, that can help.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I would also suggesting that you look at structures, since you have a set of variables that really belong in one unit (a struct or class):
    Code:
    string part;
    string des;
    float qual;
    float order;
    float quan;
    float cost;
    float total;
    should be in a struct. Then you can use an array of structs to manage all of that - it makes life A LOT easier in the long run.

    --
    Mats
    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.

  6. #6
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    how do i input anything i want into the array when i execute the first file?

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rfoor View Post
    how do i input anything i want into the array when i execute the first file?
    You make a loop that reads the individual items for each entry, and then goes on to the next element in the array.

    --
    Mats
    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.

  8. #8
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    ok say i wanted to make an if statement that if the quality on hand from a certain part was less than a number it would print that to the txt file, and all that i want to read from the file is what it printed how would i do that?
    here is my code:
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    int x;
    string part;
    string des;
    float qual;
    float cost;
    int main(){
        fstream file("Part.txt",ios::out);
        
    
    for(x=1;x<=5;x++){
    cout<<"Part Number:";
    cin>>part;
    file<<part<<endl;
    cout<<"Part Description:";
    cin>>des;
    file<<des<<endl;
    cout<<"Quality on Hand:";
    cin>>qual;
    file<<qual<<endl;
    cout<<"Unit Cost:";
    cin>>cost;
    file<<cost<<endl;}
    
    
        
    file.close();
    system("pause");
    return 0;
    }
    Last edited by rfoor; 02-11-2009 at 08:54 AM.

  9. #9
    Registered User QuestionKing's Avatar
    Join Date
    Jan 2009
    Posts
    68
    Quality on hand
    vs
    Quantity

    if the quality on hand from a certain part was less than a number it would print that to the txt file, and all that i want to read from the file is what it printed how would i do that?
    You want to know how to read everything you just wrote...?

    You seriously need to start with some tutorials on arrays like suggested. You are making a mountain out of something so simple done the right way. If you spend just 10 minutes on the array tutorial on this site you will be more prepared at attempting this program. Plus some of the answers posted will make much more sence. :\ Trust me. I am very new also, (but I have done the tutorial) and I think it will help you with this program very much. Time well spent...
    Last edited by QuestionKing; 02-11-2009 at 10:33 AM.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    I suggest having a look at indentation, as well.
    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.

  11. #11
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    is this how it is supposed to look
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    
    
    int main(){
    char part[4];
    char des[4];
    char qual[4];
    char cost[4];
    int x;

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rfoor View Post
    is this how it is supposed to look
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    
    
    int main(){
    char part[4];
    char des[4];
    char qual[4];
    char cost[4];
    int x;
    Yes, if you want 4 elements. In your previous code, you have 5 elements. And remember, with 4 elements, the indices that are valid are [0], [1], [2] and [3].

    --
    Mats
    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. #13
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    why doesnt my program get the inputted variables and print them
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    float total;
    char part[4];
    char qual[4];
    char cost[4];
    
    int main(){
        ifstream file;
      
          file.open("Part.txt");
          
      
    if (qual[0]<=150){
                      cout<<"Reorder 200 of part "<<part<<endl;
                      total=cost[0]*200;
                      cout<<"Total reorder cost:$"<<total<<endl;}
    if (qual[1]<=250){
                      cout<<"Reorder 300 of part "<<part<<endl;
                      total=cost[1]*300;
                      cout<<"Total reorder cost:$"<<total<<endl;}
    if (qual[2]<=115){ 
                       cout<<"Reorder 150 of part "<<part<<endl;
                       total=cost[2]*150;
                       cout<<"Total reorder cost:$"<<total<<endl;}
    if (qual[3]<=435){
                      cout<<"Reorder 500 of part "<<part<<endl;
                      total=cost[3]*500;
                      cout<<"Total reorder cost:$"<<total<<endl;}
    if (qual[4]<=250){
                      cout<<"Reorder 750 of part "<<part<<endl;
                      total=cost[4]*750;
                      cout<<"Total reorder cost:$"<<total<<endl;}
    
          
                   
     file.close();
    
    
    
    system("pause");
    return 0;
    }
    thanks

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    But you aren't READING anything from the file!
    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.

  15. #15
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    yeah i am im reading this program
    Code:
    #include<iostream>
    #include<cstring>
    #include<fstream>
    
    using namespace std;
    using std::string;
    
    
    int main(){
    char part[4];
    char des[4];
    char qual[4];
    char cost[4];
    char total[4];
    int x;
        fstream file("Part.txt",ios::out);
        
    
    for(x=1;x<=5;x++){
    cout<<"Part Number:";
    cin>>part;
    file<<part<<endl;
    cout<<"Part Description:";
    cin>>des;
    file<<des<<endl;
    cout<<"Quality on Hand:";
    cin>>qual;
    file<<qual<<endl;
    cout<<"Unit Cost:";
    cin>>cost;
    file<<cost<<endl;
    }
    
    
        
    file.close();
    system("pause");
    return 0;
    }

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-30-2009, 07:37 PM
  2. no match for 'operator>>'
    By Taka in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2009, 01:17 AM
  3. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 11:53 AM
  4. 2 array match
    By ajastru2000 in forum C++ Programming
    Replies: 5
    Last Post: 07-18-2003, 08: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21