Thread: whats wrong withthis prog.?

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    12

    Unhappy whats wrong withthis prog.?

    Hi, I've been haveing this really annoying problem...whenever I use 'cin' in my programs it keeps telling me 'phrase error before '<'...I went over it and made sure I declared all my variables and added all the ';' where they needed to be, but still no luck
    think before you code...

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    12
    heres the code:

    Code:
    #include <iostream.h>
    
    int main()
    {
    
    cout<<"  .oooooo.         .o.       ooooo          .oooooo.   ooooo     ooo /n";
    cout<<" d8P'  `Y8b       .888.      `888'         d8P'  `Y8b  `888'     `8' /n";
    cout<<"888              .8888.      888         888           888       8   /n";
    cout<<"888             .8' `888.     888         888           888       8 /n ";
    cout<<"888            .88ooo8888.    888         888           888       8 /n ";
    cout<<"`88b    ooo   .8'     `888.   888       o `88b    ooo   `88.    .8' /n ";
    cout<< "`Y8bood8P'  o88o     o8888o o888ooooood8  `Y8bood8P'     `YbodP'   /n";
    cout<<"                                                                    /n";
    cout<<"          ( |      (  ___  ) |__   __|( ___   (  ____ ) "<<endl;
    cout<<"          | (      | (   ) |   ) (   | (   ) || (    )| "<<endl;
    cout<<"          | |      | (___) |   | |   | |   | || (____)| "<<endl;
    cout<<"          | |      |  ___  |   | |   | |   | ||     __) "<<endl;
    cout<<"          | |      | (   ) |   | |   | |   | || ( | (    "<<endl;
    cout<<"          | (______| )   ( |   | |   | (___) || ) | (__ "<<endl;
    cout<<"          (_______/|)     (|   )_(   (_______)|/   (___) "<<endl;
    //^about ascii art was provided by at http://www.network-science.de/ascii
    //provided I had to make a few ajustments to the ascii so my compiler would accept it...
    
    int num1,opera,num2;
    
    cout<<"Welcome to K's calculator"<<endl;
    cout<<" * (shift + 8) = multiply";
    cout<<"Input order is: 'number-operation-number' NO SPACES"<<endl;
    
    cin>>"input:" num1 >> opera >> num2;
    
    switch (opera)
    {
    case '+': cout << num1 <<'+' << num2 << '=' << (num1+num2);
         break;
    
    case '-': cout << num1 <<'-' << num2 << '=' <<(num1-num2);
         break;
    
    case '*': cout << num1 <<'*' << num2 << '=' <<(num1*num2);
         break;
    
    case '/': cout << num1 <<'/' << num2 << '/' << (num1/num2);
    
         default: cout << opera <<":ERROR (@_@)" <<endl;
     }
          return 0;
    }
    think before you code...

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    148
    Code:
    	cin>>num1 >> opera >> num2;

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    12
    somehow i tried that before and it didn't work, now i tried it again and it did....
    think before you code...

  5. #5
    ___
    Join Date
    Jun 2003
    Posts
    806
    since num1 is a variable you need to put a >> in front


    Oh and when you run your program the graphics get messed up.
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

  6. #6
    Registered User slaveofthenet's Avatar
    Join Date
    Apr 2003
    Posts
    80
    The only way the input will get passed to the respective variables is if the user seperates the numbers and operator with a space, ie "1 + 1". An input such as "1+1" will deliver undesired results.
    Detailed understanding of language features - even of all features of a language - cannot compensate for lack of an overall view of the language and the fundamental techniques for using it. - Bjarne Stroustrup

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Prog won't work after i press enter...
    By emperor in forum C Programming
    Replies: 8
    Last Post: 07-04-2002, 08:47 AM
  2. whats wrong??
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 05-24-2002, 08:30 PM
  3. What did i do wrong? Code inside
    By The Rookie in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 08:14 AM
  4. Try my prog...
    By Commander in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-09-2002, 07:43 AM
  5. password prog
    By ihsir in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-06-2002, 06:39 AM