mardi 27 novembre 2018

How can I print a 1D array to be 3 x 3 and how can I have an RNG computer check values and to keep searching for an empty space?

I have been working on a 1D Tic Tac Toe project for a while now, and I am still fairly new to coding, so I have a couple questions/issues.

  • To start off, I am having issues with printing the board as a 1D String array. Primarily setting it up in the three x three fashion with the 'blanks' represented as '-'.

    //global variables
    
    static int ArrayLength = 9;
    
    static String[] board = new String[ArrayLength];
    
    static int maxVal = ArrayLength;
    
    
    static void PrntBoard() 
    
    {
        for (int cntr = '-'; cntr < maxVal; cntr++) 
    {
    
     System.out.println(board[cntr]);
    
    
           }
    }
    
    
  • I am also experiencing issues with my Computer Moves, as I keep getting errors with the computer unable to wrap around the array to eventually find an empty space and checking if a space is available in the first place.

    static void CompMove() {

    int space = 0;
    
    //keep asking till they get an empty one
    
        //have the comp random pick a spot
        space = RNG.nextInt(9);
        //check
        while (board[space].equals('X') || board[space].equals('O'));
        {
            space = RNG.nextInt(9)-1;
    
        }
    
    
    
    //fill in the game board with the valid position
    if (board[space].equals('-')) {
        board[space].equals('O');
        PrntBoard();
    }
    int lastspace = space;
    
    }
    
    

Any help would be greatly appreciated, as I am still, quite frankly, a novice and do not possess much knowledge in coding. Thank you.

C++ I need help rounding a variable for my BMI calculator, If Else statements arent working properly

First time post and also this is my 3rd program ive written so sorry in advance if i am asking the wrong questions here. So when entering 150.25lbs and 65 in I get 25.002 for my BMI, but I want to round it to 2 decimal places, making it 25.00 BMI. My program displays 25.00 but it must be using the stored value for BMI being 25.002, making it greater than 25.00 and executing the "overweight" if statement. I'm confused about how I can make it so when entering these values it will execute the "normal" if statement. Is there a way I can make a (BMI_R = BMI rounded to 2 decimal places) and use BMI_R in my if else statements?

//This program calculates the users BMI, informs the user of the range they 
fall in,
// and the amount of weight they need to gain or lose in order to fall 
within the normal range
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

float WEIGHT, HEIGHT, BMI, CHANGE_WEIGHT, UPPER_END_WEIGHT, LOWER_END_WEIGHT;
cout << "This program is designed to calculate your Body Mass Index (BMI) using your height and weight \n";
cout << "It will then determine the range that you fall in, and how much \n ";
cout << "weight you must either lose or gain in order to be in the normal range \n";

cout << "\nWhat is your weight in pounds?";
    cin >> setprecision(2) >> fixed >> WEIGHT;
cout << "What is your height in inches?";
    cin >> setprecision(2) >> fixed >> HEIGHT;

    BMI = ((WEIGHT * 703) / (HEIGHT * HEIGHT));
    UPPER_END_WEIGHT = (((HEIGHT * HEIGHT) * 25) / 703);
    LOWER_END_WEIGHT = (((HEIGHT * HEIGHT) * 18.5) / 703);  

cout << "\nYour BMI is " << setprecision(2) << fixed << BMI << endl;


if (BMI < 18.5) {
    cout << "You are Underweight \n";
    CHANGE_WEIGHT = (LOWER_END_WEIGHT - WEIGHT);
    cout << "You must gain " << CHANGE_WEIGHT << " pounds in order to fall in the Normal range \n";
}
else if (BMI >= 18.5 && BMI <= 25.0) {
        cout << "You are Normal \n";
}
else if (BMI > 25.0 && BMI <= 30.0) {
        cout << "You are Overweight \n";
        CHANGE_WEIGHT = (WEIGHT - UPPER_END_WEIGHT);
        cout << "You must lose " << CHANGE_WEIGHT << " pounds in order to fall in the Normal range \n";
}
else if (BMI > 30) {
    cout << "You are Obese \n";
    CHANGE_WEIGHT = (WEIGHT - UPPER_END_WEIGHT);
    cout << "You must lose " << CHANGE_WEIGHT << " pounds in order to fall in the Normal range \n";
}

cout << "A normal weight range for the entered height is " << LOWER_END_WEIGHT << "-" << UPPER_END_WEIGHT << "lbs.\n";

cout << "\n*Department of Health and Human Services/National Institutes of Health*\n";
cout << "BMI Values:\n";//Displays information from Department of Health and Human Services/National Institutes of Health for user
cout << "Underweight:  less than 18.5 \n";
cout << "Normal:           in the interval [18.5, 25.0] \n";
cout << "Overweight:    in the interval (25.0, 30.0] \n";
cout << "Obese:             greater than 30 \n";

    cout << "\n Program written by Dylan O'Neal\n";
    cout << " Press [ENTER] to end program";
    cin.ignore(256, '\n');
    cin.get();

}

excel if and index formula for calling multiple values

=IFERROR(INDEX(Temp!$E$2:$E$93,SMALL(IF(A$1=Temp!$B$2:$B$93,ROW(Temp!$E$2:$E$93)-2,""), ROW()-2)),"")

I am trying to add a formula to do vlookup for multiple values. A1 should be source value and if there is matching data in column B I would like to call column E data. Currently its giving me a blank cell. How can I fix this code to make it work?

I can't understand choice error codes of batch

If I have a code like this:

@echo off
choice /C BL /M "Clear screen or list actual directory"

if errorlevel 2 goto l
if errorlevel 1 goto b

:l
tree /f
goto final

:b
cls
goto final

:final

I know this actually works, but I'm confused about one thing about the errorlevel parts. I wrote first, the same code, but like this:

if errorlevel 1 goto l
if errorlevel 2 goto b

And that way it won't work properly It will only remember the errorcode 1. If you press the second option is not working.
I'm really wondering why the order of the errors matters, if a batch its supposed to execute line by line, or am i wrong?
In a nutshell, what I want to understand is how the error codes work here

Swift // NSPopUpButton .addingItems() problems

I searched a lot but I didn't find anything.. I'm relatively new to the programming world, and I am writing a little macOS software on Xcode. But there is the problem : I want to add items to a pop-up menu n°2 (NSPopUpButton) after clearing the menu when a specified item is selected in the pop-up n°1. So I made an outlet of both and wrote the if statements, but it doesn't work. In the app, when the first specified item is selected (because the first item is already selected when the app starts), the pop-up menu n°2 is showing what I want, but if I change the item to "item 2" (or in my case "Uncommon" instead of "Common") nothing happens. image showing "Common" selected when app starts // image showing "Uncommon" selected with same results than before I think that this is happening because the body of my first 'if' statement is executed, so the others aren't, but I don't know how to fix it. I tried to use 'switch' instead of 'if' or 'if/else if/else' statements but it doesn't work. I also tried to make a function of every if statement but then nothing happens. I hope you could help me. Thanks everyone.

    @IBOutlet weak var ingredientRarityNorthlands: NSPopUpButton!
    @IBOutlet weak var ingredientListNorthlands: NSPopUpButton!


   override func viewDidLoad() {
    super.viewDidLoad()


    if ingredientRarityNorthlands.titleOfSelectedItem == "Common" {
        ingredientListNorthlands.removeAllItems()
        ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsCommon)
    }
    if ingredientRarityNorthlands.titleOfSelectedItem == "Uncommon" {
        ingredientListNorthlands.removeAllItems()
        ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsUncommon)
    }

    if ingredientListNorthlands.titleOfSelectedItem == "Rare" {
        ingredientListNorthlands.removeAllItems()
        ingredientListNorthlands.addItems(withTitles: ingredientListNorthlandsRare)
    }
}

let ingredientListNorthlandsCommon = ["ok", "ko"]
let ingredientListNorthlandsUncommon = ["grer", "egr"]
let ingredientListNorthlandsRare = ["ok", "okk"]

Groovy Multiple Nested If statements

I am receiving an error on the script below, it works up until the 5th else statement and then I receive an error that simply says: "Expected EOF, found else"

When I remove the { from directly above and add it to the very bottom I no longer receive the error but the script doesn't work either.

if ((valuePlatformType.toString() == "[ai]"))
 if ((valueProductType.toString() == "Sult") || (valueProductType.toString() == "Standard") || (valueProductType.toString() == "Cx"))
    if (valueClientType.toString() == "Per") {
    allowedOptions = fieldIntegration.setFieldOptions(options.findAll {
        it.value in ["PrI", "ne", "One", "Dit", "Other"]}) 
} else {
  if ((valuePlatformType.toString() == "[Bai]"))
   if ((valueProductType.toString() == "Ct") || (valueProductType.toString() == "Complex"))
     if (valueClientType.toString() == "yer") {
    allowedOptions = fieldIntegration.setFieldOptions(options.findAll {
        it.value in ["Jn", "ST", "BPI", "Otr"]})}
} else {
     if ((valuePlatformType.toString() == "[Bi]"))
      if ((valueProductType.toString() == "Ner"))
       if ((valueClientType.toString() == "Pro")) {
        allowedOptions = fieldIntegration.setFieldOptions(options.findAll {
            it.value in ["Off", "Dest"]})}
} else {
     if ((valuePlatformType.toString() == "[D]") || (valuePlatformType.toString() == "Cise"))
       if (valueProductType.toString() == "ard")
         if ((valueClientType.toString() == "ider") || (valueClientType.toString() == "Buyer")) {
            allowedOptions = fieldIntegration.setFieldOptions(options.findAll {
                it.value in ["Regiatch", "Actch"]})}
} else {
    if ((valuePlatformType.toString() == "[Ads]"))
     if (valueProductType.toString() == "Stan")
      if ((valueClientType.toString() == "vider") || (valueClientType.toString() == "yer")) {
    allowedOptions = fieldIntegration.setFieldOptions(options.findAll {
        it.value in ["User Sync", "Fire", "tta"]})}
} else {
    if ((valuePlatformType.toString() == "[Eloa]") || (valuePlatformType.toString() == "Resp"))
     if (valueProductType.toString() == "Standard")
      if ((valueClientType.toString() == "Ber") || (valueClientType.toString() == "Prov")) {
         allowedOptions = fieldIntegration.setFieldOptions(options.findAll {
            it.value in ["Pool", "Private"]})}
} else {
    return
}

check HTML table with Python

Is it possible to read an HTML with Python and check with "if" a table data if it is true?For example:

I have this HTML:

<!DOCTYPE html>
<html>
<head>
        <title>J-Vas Beat Productions</title>
</head>
<body>
        <table style="width:100%">
                <tr>
                <th>Beat Name</th>
                <th>Producer</th> 
                <th>Beat Type</th>
                <th>Price</th>
                </tr>
                <tr>
                <td>here is name</td>
                <td>here is prod</td> 
                <td><a href="#">oldschool</a></td>
                <td>here is price</td>
                </tr>
                <tr>
                <td>here is name</td>
                <td>here is prod</td> 
                <td><a href="#">newschool</a></td>
                <td>here is price</td>
                </tr>
                <tr>
                <td>here is name</td>
                <td>here is prod</td> 
                <td><a href="#">boombap</a></td>
                <td>here is price</td>
                </tr>
        </table>
</body>
</html>

Can somehow check with Python if "Beat Type" is "old school" then enter to the link?