For a homework assignment in my intro to java class I was given the following problem: Write for, do-while, and while statements to compute the following sum and product 1. 1 + 7 + 25 + 79 + .... + (3^20 - 2) 2. 1 x 3 x 9 x 27 x 81 x ... x (3^20) I understand how to write the statements, I'm just not sure how to express the increment. For the first one (for statement) I have int i, sum = 0; for (i = 1; i =< 2486784399; // I'm not sure what would go …

Member Avatar
Member Avatar
+0 forum 6

Based on this ideea **You just wrote a loop allowing the input of 20 names into a list. Alas, you made an error as you entered name number 17. Redesign your input loop, so you can correct the error easily without having to retype the previous 16 names.** I wrote the following program #!/usr/bin/python/ env def input_numbers(): #instantiate each variable elements = [] i=0 # loop from 0 to 5 or iterate for i in range(0,5): numbers = raw_input("Enter a number:") # add each number to the list elements.append(numbers) # option chooser op = raw_input("Do you want to change an …

Member Avatar
Member Avatar
+0 forum 2

Hi Team, I have a file which contain following data like BKP0000032183140217000019 053IGZYEVSDOX .........field 2....... field3.....field4..... BKP0000032284140217000019CCTP1220 ............... BKP0000032384140217000019CA ..................... each line has 5 fields Now using shell script i am trying to extract field 4 based on condition that line start with BKP and contain code 84 and CA or CC code grep -A12 " RFND " xfer_BSPDe | grep "^BKP" >file2.txt While read line do awk '{if((substr($1,12,2)==84) && (substr($1,26,2)=='CC' || substr($1,26,2)=='CA') ) print $4;else print "0"}' done<file2.txt it is printing 0 only . any help is appreciable.

Member Avatar
Member Avatar
+0 forum 3

I have just used this code in a project which works perfectly, but I have noticed that the first record is always not displayed. Eg. the SQL query lists 15 results, but the output only displays 14, missing the first record. Any ideas why? <?php $result = mysql_query($sql); //first put all the results into an array so we can look backward and see previous items $resultSet = array(); while($record = mysql_fetch_array($rs2Dfiles)) { $resultSet[] = $record; } for ( $i = 0 ; $i < count($resultSet) ; $i++ ) { if ( $i == 0 ) { //for the first item, …

Member Avatar
Member Avatar
+0 forum 7

I'm trying to convert a number from any base between 2-36 to any base between 2-36. I have the conversion to base 10, but I'm having trouble getting it from base 10 to the desired base. Any ideas? I know part of this idea will work, I just can't get it all together syntatically. And don't worry about the checks (user inputs number 13, base 2), I'll add that at the end. Thanks! #include <iostream> using std::cout; using std::cin; using std::endl; int ToTen ( char number[15], int base, int newbase ); void ToNewBase (); int main() { char number[15]; int …

Member Avatar
Member Avatar
+0 forum 4

How can i write it so that my program only accepts positive integers that are great than or = 0? I want my program to ask "How many devices do you wish to add?" And if a user enters a letter, or anything negative it will ask them to enter it again until they enter positive that is 0 or greater. How do i tackle this?

Member Avatar
Member Avatar
+0 forum 7

I am getting an error on this code. Is it to do with whats in the while loop? How do i get it working? Basically i want to be able to take in letter or number variables, and each would output something, and if they type exit it breaks out of the loop. #include <string> string input; while (input != 'exit') { cout << "OS#: "; getline (cin, input); if (input == 'a') { cout << "hello"; } }

Member Avatar
Member Avatar
+0 forum 2

How can i create a input that only allows the letters a b c d The console will ask to please enter a letter. And they can only enter the letters a b c d. And if they enter it, it says thank you for enter a, or b or c or d.

Member Avatar
Member Avatar
+0 forum 3

I need to find a digit at a specific postion in a number. Example number 652796, user inputs a 4, "2" is displayed. I have the basis for it, but most of the time, the output is incorrect. Not sure what's wrong. #include <iostream> #include <cmath> using std::cout; using std::cin; int main () { int number = 0, digits = 0, position = 0, result = 0; cout << "Enter a number: "; cin >> number; cout << "Enter a digit position:"; cin >> position; if ( 0 == number) { cout << "0"; } while (position-- > 1) { …

Member Avatar
Member Avatar
+0 forum 2

I have coded this today and wanted to find all the data inside my database which is start_time and end_time also date which is very easy for me to validate but when it comes to time... its really hard this is what I want to do. 1. check all the data 2. validate the time 2.1 when there is no time like the user entered insert into database 2.2 but where there is a time like that or in between earlier reserved time that should be an error well i have this code here and its almost done i know …

Member Avatar
Member Avatar
+0 forum 2

number1 = 0; number2 = 0; while(number1 < 5) number1 ++; number2 += number1; Question#1 : what is the value of number1 when the loop exits? Question#2 : what is the value of number2 when the loop exits? Question#3 : if the statement number1++ is changed to ++number1, what is the value of number1 when the loop exits? Question#4 : what could you do to force the value of number2 to be 15 when the loop exits?

Member Avatar
Member Avatar
+0 forum 2

Hello, I'm using the DX Studio engine (used to develop 3d games/applications), which uses javaScript as the main language. Since the engine is not getting much attention, their forum is almost completely dead. So I thought maybe one of you here at daniWeb could help me out? When previewing my application it crashes. I'm sure it's because of the while loop, but why, I don't know: (Some of these is DX Studio events, but I just want you to look at the while loop) // Variable var run = false; // Detect if "w" key is down function onKeyChange(input) { …

Member Avatar
Member Avatar
+0 forum 4

I have a query that used union all.. and produces a table like this: `+-------------+------------------------+-----------+--------------+ | Type | Name | IDNum | Warnings | +-------------+------------------------+-----------+--------------+ | M | sample | 2013-1 | 4 | | L | sample | 2013-1 | 2 | +-------------+------------------------+-----------+--------------+` now i made a while loop to get the data under the warning column: while ($warning = mysql_fetch_objects($queryResult)){ switch($warning->Type){ case 'M': $M = $warning->Warnings;break; case 'L': $L = $warning->Warnings;break; } } but now then it only gives me the result of case M, its not looping back to check the other type to the switch case.. …

Member Avatar
Member Avatar
+0 forum 1

Hi every body.i want to make a factorial program with do while loop in the easiest way without using 'for' loop but i cant do that.please help me out!

Member Avatar
Member Avatar
+0 forum 1

<?php $dbc=mysqli_connect('localhost','root','','sam_telephone'); $query="SELECT * FROM master_name"; $result= mysqli_query($dbc,$query); $display=mysqli_fetch_array($result); echo $display['f_name']; /// its show me the result which is fine // but when i apply while loop it does not show any thing. while($y = mysqli_fetch_array($result)){ echo $y['f_name']; } // $y['f_name'] should give me a result becuase it showing me the result on line 10 why its not working on this line i dont know ?>

Member Avatar
Member Avatar
+0 forum 6

Evening Sirs, I got some problems in PHP when using while loop in tables. My problem is that I can't make the rows be the same width. This is my preview: ![11ce93daec6265124e189def81dc9696](/attachments/large/4/11ce93daec6265124e189def81dc9696.png "11ce93daec6265124e189def81dc9696") I want the blue part of the table, to be equal width with every relative white part. And the white parts to be equal with each other. Here is my CSS: table { *border-collapse: collapse; /* IE7 and lower */ border-spacing: 0; width: 100%; } .bordered { border: solid #ccc 1px; -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px; -webkit-box-shadow: 0 1px 1px #ccc; -moz-box-shadow: 0 1px 1px #ccc; …

Member Avatar
Member Avatar
+0 forum 2

Hi Everyone... I have been digging around the web for the last two days trying to fix this problem myself, but have come to the realization that I need some help. I have a mysql query that selects all country names from my country db, (works as described) I then have a select dropdown that is populated from the above query. Here is the mysql select. $result_country = $Db->query('select Country from countries order by Country Desc '); Here is the select dropdown. <select name="country" tabindex="2" class="span3" value='<?php echo $country; ?>' id="country" data-placement="right" rel="tooltip" title="Select your Country.."> <?php if($country!=''){?> <option value="<?php …

Member Avatar
Member Avatar
+0 forum 2

I am having trouble getting started with my program. I have writen the array but I am having trouble starting the if statemnent to fill the seats in the program. If they press 1 it needs to fill seats 1 through 5 if they press 2 it needs to fill seats 6 through 9. it cannot fill the same seat twice and if one section is filled it needs to go to the next. Any help would be appreciated. public class { final static int QUIT = 3 static Scanner console = new Scanner(System.in); public static void main(String[] args) { …

Member Avatar
Member Avatar
+0 forum 1

Hi everyone! So, I hereby hope to show that I've made progress in coding java (largely due to the help of this great community). I want to thank everyone for dealing with me (especially James). :) The goal: The code below is supposed to seed a layout of boats into a 2D array. This is part 1 of an excersize I've given myself - create code to seed boats horrizontally and vertically, boats must not collide, boats must not be out of bounds. The issue: Usually the layout comes out just fine. But sometimes, some boats are missing in length …

Member Avatar
Member Avatar
+0 forum 32

Hi everyone I'm studying the part about while-statement but I don't understand the explanation in the book really well and the example doesn't work for me so I can't see it with my own eyes how it works. Can someone explain what the while-statement means and does? Also can you give an example that might work?

Member Avatar
Member Avatar
+0 forum 9

hello everyone i am getting problem while configuring ntp server in rhel6 when i write nptq -p output:- no association id's returned what should i do

Member Avatar
Member Avatar
+0 forum 1

# This is an advanced guess the number game. import random # The very basis of this game. import math # Used for math.ceil import time # Used to split up long portions of text. def errorDisplay(errorCode): if errorCode == '1': print('\n\n\nError ' + errorCode + ': unlockedGameModes outside of expected scope on line 36.') def introDisplay(): # Displays the intro and defines the playerName Var. at the local scope, then returns it to the global scope. print('The Guessing Game! Now with more frustration!') playerName = input('\nHello, what is your name? ') print('\nWelcome ' + playerName + '.') print('\nThis is …

Member Avatar
Member Avatar
+0 forum 4

I have a void function that takes data from an ifstream, reads the first value, (which is an ID #), and compares that value against the ID# info from an array of records. If it's invalid, the rest of the line is ignored. If it's valid, it adds the hours worked to the hours worked field in an array of records. Here is what the input file looks like: 123 7.5 56 6.25 99 an invalid id 555 2.5 123 10.0 My issue is there is the possibility of multiple entries for the same ID# and for the life of …

Member Avatar
Member Avatar
+0 forum 3

Hello, I am new to C++ and I was trying to write a simple calculator program that has a do-while loop and also includes a series of != statements. Even though I make the statements with all the appropriate keystrokes it keeps giving me my invalid sign statement. Also, I would like to know if I used the "while" statement properly. Thank you for your help in advance =D! #include <iostream> #include <math.h> #include <string> using namespace std; int result,value; char sign; int main() { result = 0; do { cout<< "Current value is "<<result<<endl; cout<< "Please enter an operation …

Member Avatar
Member Avatar
+0 forum 8

i have problem about while loop. this my code, error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); function multiexplode ($delimiters,$string) { $ready = str_replace($delimiters, $delimiters[0], $string); $launch = explode($delimiters[0], $ready); return $launch; } function my_replace($srch, $replace, $subject, $skip=1){ $subject = explode($srch, $subject.' ', $skip+1); $subject[$skip] = str_replace($srch, $replace, $subject[$skip]); while (($tmp = array_pop($subject)) == '') ; $subject[]=$tmp; return implode($srch, $subject); } function replace_element($str,$search,$replace,$num) { $num = $num - 1; $pieces = explode(',',$str); if($pieces[$num] == $search) { $pieces[$num] = $replace; } return implode(',',$pieces); } function returnFormat($template, $subject){ preg_match_all("/\|/", $template, $matches, PREG_OFFSET_CAPTURE); foreach($matches[0] as $v) $subject = substr_replace($subject, "|", $v[1], 1); return $subject; } $replace …

Member Avatar
Member Avatar
+0 forum 4

Is there a reason why this won't take aciton or submit. I don't get any movement on the browser. Neither of the forms move. <div data-role="content"> <?php echo "<table width=\"500\" border=\"1\" cellpadding=\"4\">"; while($row = mysql_fetch_array($showEmployees)) { echo " <div data-role=\"collapsible\" data-mini=\"true\" data-content-theme=\"c\"> <h3>{$row['employee']}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$row['phone']}</h3> <p> <form action='admin.php' method='post' accept-charset='UTF-8' id='editemployee' > <div data-role=\"fieldcontain\"> <input type='hidden' name='employeeid' id='employeeid' value='{$row['id']}'/> <label for='employee' >Name:</label> <input type='text' name='employee' id='employee' value='{$row['employee']}'/><br/> <label for='phone' >Phone#:</label> <input type='text' name='phone' id='phone' value='{$row['phone']}'/><br /> <label for='management' >Management: {$row['management']}</label> <select name=\"management\" id=\"management\" data-role=\"none\"> <option value=\"0\">No</option> <option value=\"1\">Yes</option> </select><br /> <label for='active' >Active: {$row['active']}</label> <select name=\"active\" id=\"active\" data-role=\"none\"> <option value=\"1\">Yes</option> <option value=\"0\">No</option> …

Member Avatar
Member Avatar
+0 forum 11

Help me look at the codes below. It has T_IF error and T_WHILE error. The errors are on line 7 and line 18. I hope anyone can teach me to repair it and the code function is still same. <?php require_once("db.php"); session_start() if (!isset($_SESSION['cart'])) { <---T_IF error $_SESSION['cart'] = array(); } $handle = mysql_connect("baccesso_web") or die ("ERROR: Unable to open database!"); $query = "SELECT SKU, Name, Price FROM products"; $result = mysql_query($handle,$query) or die ("ERROR: Cannot execute $query."); mysql_error($handle) if (mysql_num_rows($result)>0) { <--- T_IF error while ($row = mysql_fetch_object($result)) { <--- T_WHILE error $sku = $row->Quantity $productInfo[$sku] = array() $productInfo[$sku]['Name'] …

Member Avatar
Member Avatar
+0 forum 17

I'm making a calculator that performs operations sequentially (from left to right, not precedence), using ASP.NET/C#, but I'm having trouble trying to get the loops going through the input box string in my code behind. Obviously to me the logic seems to make sense, but for some reason, I get a runtime error if I enter just a number and no operands, and while my error checking does work when it comes to ensuring there are no two operators together, it displays that error even when I have two or more sets of numbers and operands placed correctly between them …

Member Avatar
Member Avatar
+0 forum 1

My while keeps looping and i dont know why: code <?php $result = mysql_query("SELECT * FROM tag WHERE point='$pagename'"); while($row = mysql_fetch_array($result)) { $result = mysql_query("SELECT * FROM tag WHERE point='$pagename'"); //username echo $row["user"] . " ||"; //alias check $result = mysql_query("SELECT * FROM tag WHERE (user='$my_name' && point='$pagename')"); if (!$row["alias"]) { echo "As \"" . $my_name . "\"||"; } else { echo "As \"" . $row["alias"] . "\"||"; } switch ($row["role"]) { case 1: echo "Author ||"; break; case 2: echo "Illustrator ||"; break; case 3: echo "Reader ||"; break; default: echo "All "; } } ?>

Member Avatar
Member Avatar
+0 forum 4

I'm wanting to create a while loop that asks the user if he wants to run the program or not... very basic... I know. I was wanting the prompt to ask the user to input "Y" or "y" to have the program run. Like this: programStart = str(input("Please press 'y' or 'Y' to start the program")) while programStart == "Y" or programStart == "y": #program runs programStart = str(input("Please press 'y' or 'Y' to restart the program")) But it sends me an error message. why is this sending an error message not recognizing the users input?? ps: this while loop …

Member Avatar
Member Avatar
+0 forum 2

The End.