hey guys , I don't understand why the outPUT is that for the code below.. can someone please explin me how it works. Thank you. class example{ public static void main (String[]args){ int i = 1,j; while (i<=3){ j=i; while(j<=4){ System.out.println(j+" "+i); j=j+2; } i=i+1; } } } HERE IS THE OUTPUT 1 1 3 1 2 2 4 2 3 3

Member Avatar
Member Avatar
+0 forum 3

I wrote this code for an assignment that asked to create a program that calculates and displays the average of any amount of real numbers. The program is supposed to ask the user how many numbers they want to enter and then use a loop to ask the user to enter a number, keeping track of the sum as they are entered, and then calculating the average. I have it somewhat ok, until the end where it's supposed to give the average. I tried a couple things but none of them gave me the right answer. I don't think I'm …

Member Avatar
Member Avatar
+0 forum 8

I'm writing some while loops but I feel like there is a better way to write them. [CODE]int i=3; while (i<31) { cout << i << " "; i+=3; } //this one is for the first 10 terms of a sequence starting with 3 and adding 3 each time. int i=2; while (i<50000) { cout << i << " "; i*=2; } //this one is the first 15 terms starting at 2 and doubling each one.[/CODE] Is there some way to let the program know how many variables to show without figuring out how far it has to go? Also, …

Member Avatar
Member Avatar
+0 forum 5

im trying to make a simple calculator: [CODE] loop = 1 while loop == 1: print "Welcome to Jakes' Calculator" print "1) addition" print "3) multiplication" choice = raw_input("Enter a number 1-4: ") break if choice.strip() == "1": a = input("enter the first number: ") b = input("enter the second number: ") c = a + b print a, "plus", b, "equals", c elif choice.strip() == "3": a = input("enter the first number: ") b = input("enter the second number: ") c = a * b print a, "times", b, "equals", c elif choice.strip() != "1" "3" : print "Not …

Member Avatar
Member Avatar
+0 forum 2

Hi, I have a While Loop to display my MySQL info. This makes a list of all my data, in one row. But what I want is it to display it in a table with 5 columns so that the data is more readable. this is my code: [CODE] while ($row = mysql_fetch_array($retd)) { $code = $row["code"]; $name = $row["name"]; echo("<td width=150 align=center>"); echo ("<a href=../item?scode=$code><img src=pictures/$code.gif border=0 alt=Item $name</a>"); echo ("<br><a href=../item?scode=$code><span class=fs13>$name</span></a>"); echo("</td>"); } [/CODE] Now I have tried to make it like this: [CODE] <tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> [/CODE] But it didn't work, since …

Member Avatar
Member Avatar
+0 forum 8

I'm trying to simply match these letters using php, but it's kind-of a complex matching formula... First, I have two arrays and one string. The arrays contain letters and the string is a near match of those letters. $a - [Array] Must be <= 7 $b - [Array] Must be >= 0 $word - [String] Must contain letters from $a & $b. Letters can't be used twice. The Goal: Create a word from those letters with complex matching. To start each word must contain one and only one $b letter, unless no $b letters are given. Next it must make …

Member Avatar
Member Avatar
+0 forum 22

Hi all. I am learning Java, and having a problem with a sentinel loop to fill an array. I want the loop to terminate when -1 is added, OR when the array is filled. [CODE] int i = 0; int counter = 0; int[] array = new int[40]; System.out.print("Enter values to be added to the array." + " Enter -1 to stop adding values. "); array[i] = keyboard.nextInt(); while(array[i] != -1 && counter < array.length) { i++; counter++; System.out.print("Enter values to be added to the array." + " Enter -1 to stop adding values. "); array[i] = keyboard.nextInt(); } return …

Member Avatar
Member Avatar
+0 forum 13

I am writing a spellchecker program and have some issues. First thing is that I need to make better use of the memory. My code iterates through a large dictionary file repeatedly. I know its better to read this into memory first then iterate through the block but I really don't know how. The search should be optimized. The other problem is ignoring the non alphanumerical characters in the problem. Would really appreciate some help with this. [CODE]#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { /*Open files and test that they open*/ FILE *fp1; FILE *fp2; char fname[20]; char …

Member Avatar
Member Avatar
+0 forum 6

So basically I'm stuck at the do-while statement. Should I use a do while? or a for loop? This program is supposed to test my ability to use loops. [CODE]/*Create an application that reads an integer value and prints the sum of all even integers between 2 * and the input value, inclusive. Print an error message if the input value is less than 2. */ import java.util.Random; public class Project3 { public static void main (String[]args) { int critical,test,count = 2; Random rand = new Random (); critical = rand.nextInt(21); test = critical % 2; System.out.println("The random number is: …

Member Avatar
Member Avatar
+0 forum 2

I am trying to build a binary search tree. The elements in my input file is printing, but with junk. The problem is with the sentinel in the while loop. I'm not sure of what else to try. I've tried: while (infile) while (count != 14 && infile.good()) while (strcmp(Str, sentinel) != 0) But none of those are working. A sample of my input file is: meel meet food copy home link hear seed read twig tree rain quiz push ride meel And my current output file is: copy food€'M hear homeÈ'M link meeth'M push quizp(M rainX(M read@(M ride seedø'M …

Member Avatar
+0 forum 0

Hey so Im a beginner, and I need some help. My professor gave us this code: [CODE] def average(list): total = 0.0 for number in list: total += number return total / len(list) [/CODE] Then, he asked us to rewrite that program so that it uses a while loop instead. I have no idea :/ Everything I've tried so far doesn't give me the right answer. If you could please help me, I'd be forever grateful

Member Avatar
Member Avatar
+0 forum 1

Hey so Im a beginner, and I need some help. My professor gave us this code: def average(list): total = 0.0 for number in list: total += number return total / len(list) Then, he asked us to rewrite that program so that it uses a while loop instead. So far I tried and got this... def average(list): total = 0.0 i = 0 while (I < len(list)): total += list[i] i += 1 return i When I tried to run that, I kept getting the wrong answer for any list I tried. :/ If you could please help me, i'd …

Member Avatar
Member Avatar
+0 forum 3

[CODE] ifstream in_gradebook; ofstream out_gradebook; in_gradebook.open("gradeBook.txt"); out_gradebook.open("gradeBook_edit.txt"); while (???) //while int is being read { in_gradebook >> score; out_gradebook << score << " "; sum = sum + score; } average = sum / 10.0; out_gradebook << average << endl;[/CODE] Here is a small snippet of the code I have trouble with. My professor told me there's a way to end the loop when the input from in_gradebook is no longer type int, which I have no idea how to do. Basically, my loop goes on forever because the variable score gets the [U]string[/U] FIRST_NAME_2 of the second line. What …

Member Avatar
Member Avatar
+0 forum 5

Trying to make a short to do list. show item to do-->click who you are $who and $item sends to top to show that item no longer there, but the rest are [CODE] <? echo "Here is the list of things that need to be done!"; echo "<form>"; while($row3 = mysql_fetch_array($result6)) { //where and item echo "<b> Where:</b> &nbsp;" . $row3['where'] . "&nbsp; Item: &nbsp;" . $row3['item'] . "</td>&nbsp;<input type='hidden' name='submitteddone' id='submitteddone' value=\"{$row3['item']}\"><input type='checkbox' name='itemchecked' id='itemchecked' value=\"{$row3['item']}\">"; echo "</br>"; }while($row4 = mysql_fetch_array($result5)) { // Show who is clocked in echo "<span ><span style=\"padding-left:4px;\"\"><input type=\"submit\" class=\"person-in\" name=\"persondid\" id=\"persondid\" value=\"{$row4['person']}\" />"; } …

Member Avatar
Member Avatar
+0 forum 8

I am supposed to have a while loop that asks for a number until the number is a negative. Then I am supposed to get a total of all of the numbers EXCEPT the negative number. As of right now my program adds up the absolute value of all the numbers input. any suggedtions on how to add all BUT the negative? [CODE]number=float(input("Enter a number: ")) total=number while number>=0 and number<=100: number=float(input("Enter a number: ")) total+=abs(number)[/CODE]

Member Avatar
Member Avatar
+0 forum 4

Hello guys, I'm trying to make it so that the user can opt to change student's course code or credit points (they can choose to change neither, either or both) in case 5 of my main switch statement. The problem is, the loop doesn't end after you choose to do anything! The search for a student works and the prompt works, but after that, it's just a neverending loop! Any direction or advice would be awesome! Here's my whole code (I've tried making functions for things as well, but I'm no good at it!): [CODE]#include <iostream> #include <iomanip> #include <string> …

Member Avatar
Member Avatar
+0 forum 8

Building a phonebook program for school--very much a work in progress. I still need to write a sort function, tweak my delete function, etc. But actually what I'm hoping you folks could answer is hopefully simpler--for some reason I seem to have a while loop that is executing twice, and I can't figure out why. When you try to do any function, like after adding a user...the menu prints twice. Any ideas what's going on? See code (line 24 is where the while loops starts that I think is the problem): [CODE]#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct PhoneBookContacts …

Member Avatar
Member Avatar
+0 forum 8

Im having a main function issue. My program is a text analyzer of more than several lines and then input 'END' to stop taking input. It analyzes input text based on the chosen options 1 through 2, relooping for invalid choice. Im having an issue having it properly work in the main function. Here is what I have: [CODE]def input(): line = "" twodimensional = [] while line != "END": line = raw_input("") if (line != "END"): new_line = "" for char in line: if char.isalpha(): new_line += char else: new_line += " " line_list = new_line.split() twodimensional.append(line_list) return twodimensional …

Member Avatar
Member Avatar
+0 forum 1

I am making a program that analyzes text from a user After inputting several line and using the keyword "DONE", the program will ask for one of 8 possible options which is the menu() function where the user will enter the number. How would i be able to run my program using main() function to where the user will be able to enter a choice have the text analyzed according to my functions and then be prompted again until they choose to quit the program. Also a choice of numbers under 1 or greater than 8 must not work for …

Member Avatar
Member Avatar
+0 forum 1

The last do..while loop only prints the 2^n of the number entered and n is user input. It does not print all 2^n from 1 to what ever value user inputted. [CODE]/** * * * @author * @version */ //import Scanner utility import java.util.Scanner; public class Loops { public static void main(String [] args) { // For loop counts from 1 to 10 and prints results. for(int counter = 1; counter <= 10; counter++) { System.out.print(counter + " "); } System.out.println();//Skips a line // For loop that counts from 10 to 1 and prints results. System.out.println(); //Skips a line for(int …

Member Avatar
Member Avatar
+1 forum 1

Hi, This is what I'm trying to achieve...... An html table on a page which shows results from a series of races with the competitors listed on the x axis and the results per race on the y. Each series has a different number of races so it isn't possible just to hard code the race numbers. the table I'm trying to achieve should look something like [B]Race Number Competitors Details 1 2 3 4 Total points[/B] swim faster sinking 5 3 2 4 14 sunk drowned crashed 3 5 5 2 15 I can get the table to create …

Member Avatar
Member Avatar
+0 forum 2

i have to write a program that displays the value of pi for values for i = 10000,20000.....,and 100000 i have to use the following series pi = 4(1-(1/3)+(1/5)-(1/7)+(1/9)-(1/11_+...+(1/(2i +1))-(1/(2i +1)) any ideas i have to do a program with looping i cant use arrays can someone give me a hint and a strategy on how to do this problem

Member Avatar
Member Avatar
+0 forum 40

[B]What I want on the first run thru[/B] is to ask for input, print input, ask for 2nd input, print 2nd input. End the first run, saving inputs to text file. My results are: input 1 input 1 again. input 2 input 2 again. On the 2nd time thru, it works exactly the way I want it to: print all inputs in one line, (ex: input 1.input2.), ask for 3rd input, prints saved inputs + new input 3 and asks for input 4. [CODE]while True: oinp = open('open_inputs.txt','r') for line in oinp: print(line) inp = input('Enter text, or "Enter" to …

Member Avatar
Member Avatar
+0 forum 8

Hello, I am not sure why, when I call my method, it goes into a continuous loop and prints out nothing. The operator - method is suppose to be able to subtract a Date object and a Date argument. I will clarify if anything needs clarifying, thanks for the help [CODE]int Date::operator-(const Date& d) const { Date temp(myMonth,myDay,myYear); Date copy = d; int count = 0; if(temp < copy) { while (temp != copy) { temp++; count++; } return count * -1; } else if(temp > copy) { while(temp!= copy) { temp--; count++; } return count; } if(temp == copy) …

Member Avatar
Member Avatar
+0 forum 3

#include<stdio.h> #include<string.h> main() { int n; char aan = 'y'; while (aan == 'y') { printf("entr ") ; scanf ("%d", &n) ; printf("sq of %d is %d", n, n*n ); scanf ("%c", &aan); printf("\n want aan y/n""\n"); } } I want to make this using while loop. kindly tell me the problem with it. ITs not working as i want...

Member Avatar
Member Avatar
+0 forum 3

Hi all, I am a newbie to C# and need help bad. I am to use looping (do,for, while or any combination).The program will accept a letter 'A' example and then end. What am i doing wrong. Three salespeople work at Sunshine Hot Tubs-Andrea, Brittany, and Eric. Write a program that prompts the user for a salesperson’s initial (‘A’, ‘B’, or ‘E’). While the user does not type ‘Z’, continue by prompting for the amount of a sale the salesperson made. Calculate the salesperson’s commission as 10 percent of the sale amount, and add the commission to a running total …

Member Avatar
Member Avatar
+0 forum 6

hi, i put together this code to read a text file line by line, split the resulting string into the 4 values and send these values to four text-boxes. during each cycle of that while loop it's suppose to initialize the backgroundworker_dowork, which will read the values and use them(and start a long loop and stuff). The first and obvious problem i have is that when i run this i get an error saying that this backgroundworker is already busy and can't handle another task. The part that's supposed to read text works as far as i can tell from …

Member Avatar
Member Avatar
+0 forum 4

Hello! I've been stuck with this for a while now. First I want to say that this is a school project and not something illegal bet site. The first MySQL table have results from games and the other table contains users bets on different games.. My problem is that I don't know how to make the two tables compare and then by that change some numbers in MySQL table. So I want the code to look if the team1 and team2 on both tables are the same. Then look if the bets (1,X or 2) are the same. If they …

Member Avatar
Member Avatar
+0 forum 2

I have code where I am pulling data from my database and it needs to be separated by commas except the last value (that part works) so I can take those values and input into another SQL query. Here is the working code: [CODE]$biz_id = $row_businesses['id']; $query_related = sprintf("SELECT * FROM related WHERE biz_id = '$biz_id'"); $related = mysql_query($query_related, $merchant_info) or die(mysql_error()); while($row = mysql_fetch_array($related)){ $cnt++; if($cnt!=1) echo ', '; $ids = $row['requester_biz_id']; echo $ids; }[/CODE] My issue comes in when I need those values. If I take [CODE]echo $ids[/CODE] out of the last bracket, it only displays one value …

Member Avatar
Member Avatar
+0 forum 2

Hey, I have a question on how to make an inline style to this..: [CODE] $sqlCommand = "SELECT * FROM pages WHERE subjectid='" . $subjectid . "' AND showing='1' ORDER BY pos ASC"; //*** $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); $PageMenuDisplay = ''; while ($row = mysqli_fetch_array($query)) { $pid = $row["id"]; $pagelinklabel = $row["linklabel"]; $position = $row['pos']; /* Her sættes $sid=$subjectid ind i linket sammen med pid, sådan at pages ikke forsvinder og kan vises tilhørende det relevante subject */ $PageMenuDisplay .= '<li><a href="index.php?pid=' . $pid . '&amp;sid=' . $subjectid . '">>>> ' . $pagelinklabel . '</a></li>';}//*** //*** mysqli_free_result($query); …

Member Avatar
Member Avatar
+0 forum 6

The End.