Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 1 month ago

noob c++ ?

why does cin>>select no worky       

i want  select to = wp which = 25 then display gae

i have to type cin>>25 instead of just typing cin>>wp WHYYY

#include <iostream>

using namespace std;

int main(){

int wp = 25;

int select;

cin>> select;

if (select =25){

cout<<"gae"<<endl;

}

cin.get();

cin.get();

}

3 Answers

Relevance
  • 1 month ago
    Favorite Answer

    For one thing

    (maybe THE thing)

    your "if" statement is incorrect.

    Very common "noob" mistake

    you need to put ==, not =

    when you put (select=25) in the if statement

    you are ASSIGNING the value 25 to the variable "select".

    So

    if (select=25)

    will ALWAYS return "true"

    but

    if (select == 25)

    will only return "true" if select has previously been assigned the value of 25.

    • Log in to reply to the answers
  • Anonymous
    1 month ago

    if (select =25){ will assign 25 to select, then test select is non-zero!

    to do a test either replace = with == for a comparison or use the equal_to object:-

    #include <iostream>

    #include <functional>

    int main(){

      int select;

      std::cin >> select;

      if (std::equal_to<int>()(25, select)){

         std::cout<<"gae"<<std::endl;

      }

    }

    • Log in to reply to the answers
  • EddieJ
    Lv 7
    1 month ago

    (select =25)

    should be

    (select == 25)

    You need 2 equal signs to test for equality.

    • Log in to reply to the answers
Still have questions? Get answers by asking now.