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

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, you are not. You are trying to store input into an array, without specifying WHERE in the array you want to store it, and you are especially not writing to the file.
    And you really MUST fix your indentation!
    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.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Does that compile?

    Assuming you were reading into part[i], then your loop goes from 1 to 5, which is outside the range of 0..3 that part[4] allows you to use.

    --
    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. #18
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    both of them do compile and it goes 0(1),1(2),2(3),3(4),4(5) so there are 5 inputs right, ?

    should i do something different when i write it to the file?
    Code:
    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;}

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    After looking at it again, I realize why it compiles: You are reading a string - char part[4] is a string in C (and thus C++). So you are not actually reading into an array (in the general meaning of array - strictly speaking, C style strings are of course arrays, but that's not what any of use meant when we said "use an array"). Of course, in this case, you are just outputting what you input, so it doesn't really matter how you read it in - using arrays would not really mean much in THIS case - as long as you don't enter anything longer than 3 digits or letters, as the array is 4 characters long, and you need a zero-character at the end of the string.

    And as to the index of an array with n elements: You write that as
    Code:
    T arr[n]
    (T is any valid type, n is some integer constant type). You then have valid valuse for [x] in the range 0..n-1. So
    Code:
    int array[4];
    will have four elements, with the index 0, 1, 2 and 3. Note that what you write in the declaration of the array is THE NUMBER OF ELEMENTS, and then use the indices up to one less than the number of elements.

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

  5. #20
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    how would i get the data to be input into the array with a loop on it
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    
    
    int main(){
    int array1[4];
    int array2[4];
    int array3[4];
    int array4[4];
        
    int x;
        fstream file("Part.txt",ios::out);
        
    
    for(x=1;x<=5;x++){
                      cout<<"Part Number:";
                      cin>>array1;
                      file<<array1<<endl;
                      cout<<"Part Description:";
                      cin>>array2;
                      file<<array2<<endl;
                      cout<<"Quality on Hand:";
                      cin>>array3;
                      file<<array3<<endl;
                      cout<<"Unit Cost:";
                      cin>>array4;
                      file<<array4<<endl;}
    
    
        
    file.close();
    system("pause");
    return 0;
    }

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    cin >> array1[n];
    Where n is the index in the element to store the result.

    And fix your indentation already!!
    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.

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And you still have a loop that goes TWO places outside of the array, if you use [i] as the index when reading the input. This is because you start on 1 and end on 5, whilst your array has elements 0..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.

  8. #23
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    ok my program crashed
    here is the data im supposed to use:
    Part Number: XL101, XM215, XR218, XG321, XK178
    Part Description: Grommet, Chuck, Lathe, Lug, Appeture
    Quantity on hand: 125, 254, 111, 654, 235
    Reorder Point (when the quantity on hand reaches or falls below this amount): 150, 250, 115, 435, 250
    Reorder Quantity: 200, 300, 150, 500, 750
    Unit cost: 1.34, 1.77, 4.23, 6.12, 1.54

    and heres my code that crashes
    Code:
    #include<iostream>
    #include<string>
    #include<fstream>
    
    using namespace std;
    using std::string;
    
    
    int main(){
    char array1[100];
    int n;
    char array2[200];
    float array3[50];
    float array4[50];
    int x;
        fstream file("Part.txt",ios::out);
        
    
    for(x=1;x<=5;x++){
                      cout<<"Part Number:";
                                  cin>>array1[n];
                                                 file<<array1[n]<<endl;
                      cout<<"Part Description:";
                                  cin>>array2[n];
                                                 file<<array2[n]<<endl;
                      cout<<"Quality on Hand:";
                                     cin>>array3[n];
                                                    file<<array3[n]<<endl;
                      cout<<"Unit Cost:";
                                  cin>>array4[n];
                                                 file<<array4[n]<<endl;}
    
    
        
    file.close();
                 system("pause");
                                 return 0;
                                                 }

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    But you are not listening to what we say!
    You have YET to fix the indentation.
    And you have YET to fix the loop itself!
    Go back and read the previous replies before you do anything more, and before you reply, fix everything that the previous replies mentioned.

    After you've done that, I will tell you what's wrong with the 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.

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, first of all 'n' that Elysia talks about is "a number indicating which element in the array you are referring to". In your case, n is a new variable, and it's got no value at all - bad idea. You probably want to use i, rather than n.

    Second, part is supposed to be a text string, which is an array of char in itself.

    Third. why are you using anonymous names such as array1 and array2 - much better to call them something that reflect what the actual content is.

    Fourth, what is the purpose of loading the values in an array when you are just storing it to write out again?


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

  11. #26
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    im storing it in a txt file so i can read it with another program.
    as i said earlier if it a part quality is below the reorder point it will write a line that says you must reorder that part now!
    how would i type that if statement?
    i was thinking something like this
    Code:
    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;}
    any suggestions?

  12. #27
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is it somehow impossible for you to read some lines in a reply?
    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.

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

    Talking

    what do you want me to do indent it until you cant see the code on the screen
    Last edited by rfoor; 02-13-2009 at 08:44 AM.

  14. #29
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rfoor View Post
    what do you want me to do indent it until you cant see the codehttp://cboard.cprogramming.com/images/icons/icon10.gif
    No, just so that the code is readable.

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

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is that what you call indentation?
    I call this indentation:
    Code:
    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;
    }
    And another snippet:
    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;
    }
    This is by no means good looking code, but at least it's readable.
    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.

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