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
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Help I want to change While loop to Nested for loo

Help I want to change While loop to Nested for loo

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++game-devregexquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JawedVikia80
    wrote on last edited by
    #1

    Hi friends i am new to c++ and also in the forum this question is my experiment .Now problem is that , i want to change the while loop to the nested for loop. The program's description is as follows :- Writ a program for a Match stick game between the computer and user . Program should ensure that the computer always wins . Rules for the Game are as follows:- -There are 21 match sticks. -The computer asks the player to pick 1, 2 ,3, or 4 match sticks . -After the person picks , the computer does its picking . -However is forced to pickup the last match stick looses the game . The programs code is as under /*Match Stick Game */ # include # include void main () { int m = 21,p,c; clrscr(); while(1) { printf("\n\nNo.of matches left = %d",m); printf("\npickup 1,2,3,or 4matches"); scanf("%d",&p"); if(p>4||p< 1) continue; m = m -p; printf("\n\nNo. of matches picked up %d",c); m =m-c; if(m== 1) { printf ("\n\nNumber of matches left %d" ,m); printf("\nYou lost hte Game !!"); break; } } printf("\n\n\n\n\nPress any key to Exit..."); getch(); }

    J 1 Reply Last reply
    0
    • J JawedVikia80

      Hi friends i am new to c++ and also in the forum this question is my experiment .Now problem is that , i want to change the while loop to the nested for loop. The program's description is as follows :- Writ a program for a Match stick game between the computer and user . Program should ensure that the computer always wins . Rules for the Game are as follows:- -There are 21 match sticks. -The computer asks the player to pick 1, 2 ,3, or 4 match sticks . -After the person picks , the computer does its picking . -However is forced to pickup the last match stick looses the game . The programs code is as under /*Match Stick Game */ # include # include void main () { int m = 21,p,c; clrscr(); while(1) { printf("\n\nNo.of matches left = %d",m); printf("\npickup 1,2,3,or 4matches"); scanf("%d",&p"); if(p>4||p< 1) continue; m = m -p; printf("\n\nNo. of matches picked up %d",c); m =m-c; if(m== 1) { printf ("\n\nNumber of matches left %d" ,m); printf("\nYou lost hte Game !!"); break; } } printf("\n\n\n\n\nPress any key to Exit..."); getch(); }

      J Offline
      J Offline
      Jon G
      wrote on last edited by
      #2

      This sounds like homework to me :) ---------- int Value; for (int i = 21; i > 0; i=i) { Console::WriteLine("Pick 1,2,3 or 4: "); Value = Console::Read(); if (Value <= 4 && Value >= 1) i = i - Value; else Console::WriteLine("Not a valid choice"); if (i <= 0 ) Console::WriteLine("Game over"); } Console::WriteLine("Press enter to continue"); Console::Read();

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

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