Thread: || or starements

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    22

    || or starements

    hey only in 4th week of learning c++ just wanted to know what this error message means for this program, i am using dev c++ as a compiler:

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main()
    
    {
    	          
    	           double answer = 0, userinput = 0, convertback = 0;
    	           int convert =0, modcon = 0, modcon1 = 0, wholenum = 0, cents = 0, cents1 = 0;
    	           
    	            	cout << setiosflags(ios::fixed);
                      	cout << setiosflags(ios::showpoint);
                       	cout << setprecision(2);
    
                             cout<<"Please enter a sum of money and i will round it to the  nearest 5 cents for you: ";
                             cin>>userinput;
                             
                                            convert =(int)(userinput*100);
                                            modcon =(convert&#37;100);
                                            wholenum =(convert-modcon);
                                            modcon1 =(modcon%10);
                                            
                                            
                                                    if (modcon1 >= 3 || <=7)
                                                   {
                                                       modcon1 =((modcon/5 + 1)*5);
                                                       }else if (modcon1 <=2 || >=8)
                                                       {
                                                             modcon1 =((modcon/5)*5);
                                                             }
                                                       
                                                      cents =(modcon-modcon1);
                                                      cents1 =(cents+modcon1);
                                                      convertback =(double)(wholenum+cents1);
                                                      answer =(convertback/100);
                                                      
                             cout<<"The Answer is: "<<endl;
                             
              return 0;
              
    }
    error saying - expected primary-expression before '<=' token
    appeared for || or statement, sorry if i dodnt give enough info here or something but i think thats all you need.....
    thnx in advance and i know its not finished yet
    Last edited by grimuth; 08-19-2007 at 05:42 AM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    if (modcon1 >= 3 || modcon1 <=7)
    Kurt
    Edit: but then this is alwais true

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    22
    haha thnx just needed to enter name after || or statement

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You'll need && if you want to check if modcon is in range 3...7 (both conditions must be true).

    And if you fix this
    Code:
    if (modcon1 >= 3 && modcon1 <= 7) {
       ...
    }
    else if (modcon1 <= 2 || modcon1 >= 8) {
       ...
    }
    the red part becomes redundant: if the program execution gets to the else part, this condition will always be true.
    Last edited by anon; 08-19-2007 at 07:14 AM.
    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).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  2. process killer on a loop
    By Anddos in forum Windows Programming
    Replies: 8
    Last Post: 01-11-2006, 01:50 AM
  3. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  4. Massive Function Problem
    By Marc Sharp in forum C Programming
    Replies: 10
    Last Post: 11-19-2003, 08:49 PM
  5. Tic Tac Toe Help
    By aresashura in forum C++ Programming
    Replies: 1
    Last Post: 11-21-2001, 12:52 PM