Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
S

StateofMind09

@StateofMind09
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Trouble with loops
    S StateofMind09

    I've got an assignment that I've been struggling with all day, and after re-doing the program several times I believe I've narrowed down my problem to this:

    #include #include int random;
    int guess;
    char play = 'y';
    int game = 1;

    int main()
    {
    while(game == 1)
    {
    if(play == 'y')
    {
    random = 1 + rand() % 1000;

    	printf("\\nI have a number between 1 and 1000.\\nCan you guess my number?\\nType your first guess:");
    
    	play = 'v';
    
    }
    	scanf("%i",&guess);
    
    	if(guess == random)
    	{
    		printf("\\nExcellent! You guessed the number!\\nWould you like to play again?(y/n)");
    		scanf("%c",&play);
    		if(play == 'n')
    		{
    			 game = 0;
    		}
    	}
    
    	else
    	{
    		if(guess < random && guess != random)
    		{
    			printf("\\nToo low, try again!");
    		}
    
    		if(guess > random && guess != random)
    		{
    			printf("\\nToo high, try again!");
    		}
    	}
    }
    
    	return 0;
    

    }

    When I enter the if(guess == random){} block and answer the (y/n) question, the program falls apart. No matter what I seem to do, it'll shut down, stop functioning, or repeat that block once more before it moves on to what it's supposed to do. I don't understand what I'm doing wrong.

    C / C++ / MFC question game-dev help lounge
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups