Thread: Please check this!?

  1. #1
    Registered User zergdeath1's Avatar
    Join Date
    Sep 2003

    Please check this!?

    int book = 0, write = 0, research = 0, start, lev = 1, cmd;
    float money = 0, rate = 0;
    printf ("Before we start how much money do you want to play for? (No Decimal):");
    scanf ("%d", &start);
    printf ("This is a simple program designed after learning to code\n");
    printf ("Your Objective is to make %d dollars. In order to get this much money you will have 3 skills\reading, writing, and research. \nIn order to grow in these skills you will have to complete those tasks.\nNow in order to make money you need to use your skills to write a program, \nthen sell it the amount of money you make will be determined by your skill level.\nIn order to grow in skill you must have 1 level \nmore in reading, writing, and reasearch than your level.", start);
    while (1){
    if (money==start) { printf ("you win"); return 0;}
    switch (lev) {
           case 2: rate=rate+10;break;
           case 3: rate=rate+20;break;
           case 4: rate=rate+30;break;
           case 5: rate=rate+40;break;
           case 6: rate=rate+50;break;
           case 7: rate=rate+60;break;
           case 8: rate=rate+70;break;
           case 9: rate=rate+80;break;
           case 10: rate=rate+90;break;
           case 11: rate=rate+100;break; }
    if (book==1 && write==1 && research==1)
    if (book==2 && write==2 && research==2)
    if (book==3 && write==3 && research==3)
    if (book==4 && write==4 && research==4)
    if (book==5 && write==5 && research==5)
    if (book==6 && write==6 && research==6)
    if (book==7 && write==7 && research==7)
    if (book==8 && write==8 && research==8)
    if (book==9 && write==9 && research==9)
    if (book==10 && write==10 && research==10)
    if (book==11 && write==11 && research==11)
    if (book==12 && write==12 && research==12)
    printf("\nYou have 5 commands to choose from: 1.Stats, 2.Read, 3.Write, 4.Research, 5.Game (Writes for money).");
    printf("Insert Command #: ");
    scanf("%d", &cmd);
    if (cmd == 1)
       printf("Stats:\n\nReading: %d\nWrite: %d\nResearch: %d\nLevel: %d\nRate: %.0f\nMoney: %.2f", book, write, research, lev, rate, money);
    if (cmd == 2)
       printf("Reading. . . . . .");
       sleep (10000);
       continue; }
    if (cmd == 3)
       printf("Writing. . . . . .");
       sleep (10000);
    if (cmd == 4)
       printf("Researching. . . .");
       sleep (10000);
    if (cmd == 5)
       printf("Selling. . . . . .(Takes Longer)");
       sleep (50000);
       money = money + rate;
    return 0;
    What is wrong with this? The rate will never increase!?
    Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
    My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?

  2. #2
    Registered User
    Join Date
    Oct 2001
    In order for lev to increase:
    book, write, and research all have to be the same value(either all=1, all=2, etc.)
    Once lev=2 or greater, rate will increase.

    If one of the three is different, for example:
    book=2, write=1, and research=1, lev won't increase.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    What's with all the continues? Shouldn't you just be using an if/else ladder or a switch? It would be much cleaner.

    To further Swoopy's point:

    You could also make this much simpler, without even needing another variable.

    if( a > level && b > level && c > level )

    That replaces all of those if statements down below. When all skills are at 1, which is what level starts at, nothing happens. Say you train up 'a' four times. Now you train 'b' twice and 'c' twice.

    In the above example, your code will fail. Mine however will bump you to level 2. You could even throw that in a loop and make it so if you bought ten of 'a', then ten of 'b' and finally ten of 'c', it would increase your level each time you bought 'c'.

    a=10, b=10, c=1, level = 1
    a=10, b=10, c=2, level goes to 2
    a=10, b=10, c=10, level goes to 10

    The above wouldn't be possible in your version of the if checks.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. how to check input is decimal or not?
    By kalamram in forum C Programming
    Replies: 3
    Last Post: 08-31-2007, 07:07 PM
  3. Please check this loop
    By Daesom in forum C++ Programming
    Replies: 13
    Last Post: 11-02-2006, 01:52 AM
  4. A way to check for Win98 or WinXP
    By Shadow in forum A Brief History of
    Replies: 5
    Last Post: 10-31-2002, 11:06 AM
  5. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2002, 11:21 PM