wierd Problem on Small If Prog

This is a discussion on wierd Problem on Small If Prog within the C++ Programming forums, part of the General Programming Boards category; This is the code Code: #include <iostream> #include <stdlib.h> using namespace std; int main() { int a; char C; cout<<"Why ...

  1. #1
    God
    God is offline
    Registered User
    Join Date
    Jul 2004
    Posts
    2

    Question wierd Problem on Small If Prog

    This is the code
    Code:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    
    int main()
    {
      int a;
      char C;
      cout<<"Why Hello ";
      cout<<"What lang you think this is in? ";
      cin>>a;
      if(a==C++)
      (
        cout<<"You got it";
      )
      else
      (
         cout<<"Nope Its C++ ";
         
      )
      system("PAUSE");	
      return 0;
    }
    yes its cheezy but its to someone who only does qbasic
    the error i get is on the line cout<<"You got it"; the error is parse error before";" i have no clue what it is im am working in devc++ any help would be appreciated. o in case its no obvious i am new and learning
    Last edited by God; 07-11-2004 at 04:27 AM.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    You can't compare it like that youd have to do something like this
    Code:
    #include <iostream>
    #include <string>//for strcmp()
    #include <stdlib.h>
    
    using namespace std;
    
    int main()
    {
      
      char c[20];
      cout<<"Why Hello ";
      cout<<"What lang you think this is in? ";
      cin>>c;
      if(strcmp(c,"c++")==0)
      {//These need to be braces not paratheses'
        cout<<"You got it";
      }
      else
      {
         cout<<"Nope Its C++ ";
         
      }
      system("PAUSE");	
      return 0;
    }
    Oh and welcome to the boards
    Last edited by prog-bman; 07-11-2004 at 04:50 AM.
    Woop?

  3. #3
    God
    God is offline
    Registered User
    Join Date
    Jul 2004
    Posts
    2
    Thank You very much though i will have to look up strcmp that does fix what was wrong thanks again

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <string>
    
    using namespace std;
    
    int main()
    {
      int a;
      string input;
      cout<<"Why Hello ";
      cout<<"What lang you think this is in? ";
      cin>>input;
      if(input=="C++")
      (
        cout<<"You got it";
      )
      else
      (
         cout<<"Nope Its C++ ";
         
      )
      system("PAUSE");	
      return 0;
    }
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  5. #5
    Banned
    Join Date
    May 2004
    Posts
    55
    change int a to char a[25] and it will work

  6. #6
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    Quote Originally Posted by Noxir
    change int a to char a[25] and it will work
    you're my kind of c board poster
    .sect signature

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    you're my kind of c board poster
    The kind that spit out useless garbage? I think we have enough of those

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by ggs
    you're my kind of c board poster
    in that case, does ggs wanna explain how that little change would work?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wierd Malloc Problem
    By mohankarthik in forum C Programming
    Replies: 11
    Last Post: 09-17-2008, 02:14 PM
  2. wierd problem with gcc
    By abh!shek in forum C Programming
    Replies: 3
    Last Post: 07-02-2008, 11:16 AM
  3. a very small problem, i'm new... please help?
    By Uberverse in forum C++ Programming
    Replies: 9
    Last Post: 11-10-2007, 09:44 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM

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