Sign in to follow this  

Function Problem

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a program that runs a while loop, and if the user enters "test", the function test should run,(which outputs "this is from test"), but nothing happens.What is going on?Heres the code im dealing with:
 while (i = 1)
    {
        
        std::cin>>command;
        if (command == 'test')
        {
                Test();
                
        }
       
    }

Share this post


Link to post
Share on other sites
The problem is, you've declared "command" as type char, without realizing that that only holds 1 character rather than a string of characters. Declare "command" as a std::string, rather than a char.

Share this post


Link to post
Share on other sites
i think the problem lies with your condition in the while (blah)

while (i = 1)

try while (i == 1)

since '=' is the assignment operator, which assigns the right hand value to the laft hand variable.

and '==' being the equality operator.

hopefully somewhere in your code you have something that sets i to something other than 1, otherwise, since i is always 1, it will get stuck in an infinite loop. which isnt nice

Share this post


Link to post
Share on other sites

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this