• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:58
CEST 13:58
KST 20:58
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Reynor: GSL Loss Wasn't About Preparation Format12[IPSL] Spring 2026 Grand Finals - This Weekend!3Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Is the larve respawn broken? BGE Stara Zagora to be held again in June 2025 Weekly Cups (July 6 - 12): Protoss strike back Serral wins HomeStory Cup 29 Yamato Cup Series
Tourneys
WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29 Vespene Cup #1 — $300+ USD, July 10
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Etiquete rules in Asl? Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) screpdb: new Starcraft reporting tool ASL 22 Proposed Map Pool
Tourneys
[IPSL] Spring 2026 Grand Finals - This Weekend! Escore Tournament - Season 3 [Megathread] Daily Proleagues [ASL22] Wildcard Qualifier
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
General RTS Discussion Thread Path of Exile Nintendo Switch Thread Stormgate/Frost Giant Megathread Summer Games Done Quick 2026!
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread UK Politics Mega-thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion! Series you have seen recently...
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Tennis[sport] Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7441 users

The Big Programming Thread - Page 213

Forum Index > General Forum
Post a Reply
Prev 1 211 212 213 214 215 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
omarsito
Profile Joined June 2011
22 Posts
December 10 2012 00:47 GMT
#4241
I'm wondering if anyone has a idea for a novice program with objects in java, i've currently finished three programs for my programming course which has to include your own made objects but i can't think of what to do for the last program. I'd be thankful if anyone could just throw me a idea!
Mr. Wiggles
Profile Blog Joined August 2010
Canada5894 Posts
December 10 2012 01:12 GMT
#4242
On December 10 2012 09:47 omarsito wrote:
I'm wondering if anyone has a idea for a novice program with objects in java, i've currently finished three programs for my programming course which has to include your own made objects but i can't think of what to do for the last program. I'd be thankful if anyone could just throw me a idea!

Make a card game. Blackjack is easy, but you could go as complex as you'd like, depending on which game you use.

It works pretty intuitively as far as objects go, you can have stuff like Players, Hands, Cards, Decks, etc., or however you decide to implement it.
you gotta dance
white_horse
Profile Joined July 2010
1019 Posts
December 10 2012 01:20 GMT
#4243
On December 10 2012 08:51 Marradron wrote:
Show nested quote +
On December 10 2012 08:34 white_horse wrote:
How do you "scale" an array so that its maximum value is 1? Our professor wants us to do that to the array "body" (below) but I have no idea what that means. This is for MATLAB not c++,


Row = 30;
Col = 40;
body = zeros(Row, Col);


A =

2 3
5 7

>> A=A./max(A(: ))

A =

0.2857 0.4286
0.7143 1.0000

Bassically you scale the array by the maximum value in the array.

One problem is that the array in your code is defined as an array with only zeroes. For that case it is not clear what the professor wants.


cool thank you
Translator
dapierow
Profile Blog Joined April 2010
Serbia1316 Posts
December 10 2012 07:47 GMT
#4244
Hey guys, I need a bit of help with PHP.

I have a user click a link in a list for the content he wants to see on the next page.
the problem is that each one of the options is a line in a file with a delimiter of ~ for each part of the page.

I know how to read it if each page is a different text file but how would I do this?

I know how to explode the delimiter, but how do I explode each line aswell?
Eat.Sleep.Starcraft 2
AmericanUmlaut
Profile Blog Joined November 2010
Germany2596 Posts
Last Edited: 2012-12-10 14:27:57
December 10 2012 10:56 GMT
#4245
On December 10 2012 09:47 omarsito wrote:
I'm wondering if anyone has a idea for a novice program with objects in java, i've currently finished three programs for my programming course which has to include your own made objects but i can't think of what to do for the last program. I'd be thankful if anyone could just throw me a idea!

I like a basic adventure game as an object-oriented exercise, since it allows for using inheritiance in a fairly intuitive way: Creatures have HP, MP, and stats. Player derives from Creature and has inventory, spells, equipped weapons, experience points, etc. Objects have HP (if you want everything to be destructible), value in gold, and weight. Item derives from Object and defines slots in which it's allowed to be equipped. Weapon derives from Object and has damage. And so on.

One of the problems with learning inheritance is that it can be a fairly abstract concept. Mapping your classes to familiar things and then figuring out what commonalities they have to derive parent classes makes the process more intuitive for a beginner.
The frumious Bandersnatch
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
December 10 2012 11:07 GMT
#4246
On December 10 2012 16:47 dapierow wrote:
Hey guys, I need a bit of help with PHP.

I have a user click a link in a list for the content he wants to see on the next page.
the problem is that each one of the options is a line in a file with a delimiter of ~ for each part of the page.

I know how to read it if each page is a different text file but how would I do this?

I know how to explode the delimiter, but how do I explode each line aswell?

Can't you just explode the line delimiter first, then do a loop and explode the part delimiters?

So if you have part1~part2$part3~part4, and $ is a delimiter for the lines, you would explode $, then loop through the resulting array, exploding the ~. You could save the results in a 2d array. If you grab them from the file so there's no line delimiter, I assume you could explode on "\n" for the lines?
neSix
Profile Blog Joined November 2004
United States1772 Posts
December 10 2012 15:54 GMT
#4247
On December 10 2012 09:19 Poopi wrote:
Hey guys.
So I just finished a project (well there is this problem so it's not literally finished) in PHP with some mySQL.
However I had a problem with a basic search bar. It won't matter since I already sent my project, with the problem, because of the deadline, but my curiosity wants to know what was the solution for this problem. I could not really find the right key words on google so here I ask you if you can help me.

So I want the request to search in a precised table the word typed, but I want it to only show the results from this table associated with the current userid.
Here is my request showing it but for every id :
SELECT * FROM products WHERE name LIKE '%$search%' ORDER BY name

(not sure about the syntax Im on mobile don't have access to the files).
I would like something like that instead :
SELECT * FROM products WHERE fournid='$fournid' AND name LIKE  etc

$search the $_post of the searchbar and $fournid the $_cookie['userid'] of the current user.
Problem this request won't work and I know it but I don't know how I'm supposed to do it.

Any ideas?
Thanks in advance.


Well, right off the bat I noticed that you're using quotes to compare the value in the fournid column... the fact that it ends with id suggests to me that this is actually an integer field and thus you shouldn't be using quotes.

Other than that, both queries looks fine to me. It's impossible to say what is going wrong without knowing the schema of your tables. I think it's worth noting that while I of course don't know anything about your problem domain, the notion of having a "user id" column on a product table suggests something grossly incorrect with your design...
FFGenerations
Profile Blog Joined April 2011
7088 Posts
Last Edited: 2012-12-10 16:04:59
December 10 2012 16:04 GMT
#4248
does this help?


SqlCommand sqlCom = new SqlCommand("UPDATE StudentInfo SET StudentFirstName ='" + takeStudentFirstName + "', StudentSurname ='" + takeStudentSurname + "', CourseID ='" + takeCourseID + "'WHERE StudentID = " + combospStudentID.Text, dbconn);


do shit WHERE studentID = (name of your combo box.Text)

my whole page
+ Show Spoiler +


using System;
using System.Collections.Generic;
using System.ComponentModel; // *****************************
using System.Data; //
using System.Drawing; //
using System.Linq; // *****************************
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient; // We're going to be using sqlclient library

namespace WindowsFormsApplication1
{
public partial class StudentPage : Form // Here's our StudentPage form
{
private string connectionString = "user id=TestUser;password=password;server=PERCY-PC\\SQLEXPRESS;Trusted_Connection=yes;database=Enrolment";
// Here we give our database connection info, including path, title; in this case we've called the database "Enrolment"

public StudentPage()
{
InitializeComponent();

combospStudentID.Items.Clear(); // Make sure our combo box is clear

SqlConnection dbconn = new SqlConnection(connectionString); // Create the database connection using our (connectionString)

try
{
dbconn.Open(); // Open the connection
}
catch // If the above fails, show this error message..
{
MessageBox.Show("Connection to database failed. Please check and try again.");
}

SqlDataAdapter sqlAdapt = new SqlDataAdapter("SELECT * FROM StudentInfo", dbconn);
// Query the database. We are wanting to fill our combobox with StudentIDs, so we retrieve all from the database...

DataTable dt = new DataTable();
sqlAdapt.Fill(dt); // ...and put this data into a temp datatable.

foreach (DataRow dr in dt.Rows) // We can now fill our combobox with StudentIDs (do it for each row in the datatable until exhausted).
{
combospStudentID.Items.Add(dr["StudentID"]);
}

dbconn.Close(); // Close the database connection now it is no longer needed.
}

private void button2_Click(object sender, EventArgs e)
{
this.Close();
AddStudent ac = new AddStudent(); // This button closes the current page and takes us on to Add Student page.
ac.ShowDialog();
}

private void button1_Click(object sender, EventArgs e)
{
this.Close(); // This is our "back" button which will get us back to the Welcome page menu.
}

private void spcomboStudentID_SelectedIndexChanged(object sender, EventArgs e)
// This is going to be what happens when we select an item in the StudentID combo that we filled earlier

{
SqlConnection dbconn = new SqlConnection(connectionString); // Get ready with a new connection
try
{
dbconn.Open(); // Open the connection
}
catch
{
MessageBox.Show("Connection to database failed. Please check and try again."); // Just incase!
}

SqlDataAdapter sqlAdapt = new SqlDataAdapter("SELECT * FROM StudentInfo WHERE StudentID = '" + combospStudentID.Text + "'", dbconn);
// Here we retrieve everything in a row from StudentInfo table where that row's StudentID is equal to the StudentID we
// selected in our combo box!

DataTable dt = new DataTable();

sqlAdapt.Fill(dt); // Stick it in a datatable

foreach (DataRow row in dt.Rows) // And now use it to fill our textboxes, outputting the relevant Firstname, Surname
{
txtspFirstName.Text = row["StudentFirstName"].ToString();
txtspSurname.Text = row["StudentSurname"].ToString();
}

SqlDataAdapter sqlAdapt2 = new SqlDataAdapter("SELECT * FROM StudentInfo INNER JOIN CourseInfo ON StudentInfo.CourseID=CourseInfo.CourseID WHERE StudentID = '" + combospStudentID.Text + "'", dbconn);
// We're not finished yet. We're outputting a Firstname & Surname alongside the associated StudentID..
// But we also want to output a CourseName & CourseID that are associated with our selected student's CourseID.
// We join the StudentInfo table to the CourseInfo table, and the CourseIDs on these match up together, allowing us to retrieve..

DataTable dt2 = new DataTable();
sqlAdapt2.Fill(dt2); // ...fill a datatable...

foreach (DataRow dr2 in dt2.Rows)
{
txtspCourse.Text = dr2["CourseName"].ToString(); // ...and output the relevant values to our GUI textboxes.
txtCourseIDgo.Text = dr2["CourseID"].ToString();
}

dbconn.Close(); // Close the connection. Take a deep breath.

}

private void button4_Click(object sender, EventArgs e) // This is surely our delete button.
{
SqlConnection dbconn = new SqlConnection(connectionString);
try
{
dbconn.Open();
}
catch
{
MessageBox.Show("Connection to database failed. Please check and try again.");
}

SqlCommand sqlCom = new SqlCommand("DELETE FROM StudentInfo WHERE StudentID = " + combospStudentID.Text, dbconn);
// Here we have connected to the database, and are now requesting a deletion from StudentInfo where StudentID is equal
// to the Student ID we have selected in our combo box.

try
{
sqlCom.ExecuteNonQuery();
}
catch // Our code doesn't know what to delete if we don't have a Student ID selected in the combo box (ie if nothing is selected)..
// ..so to avoid any problems we provide an informative error message if the ExecuteNonQuery() fails.
{
MessageBox.Show("Please select a Student ID to delete a student.");
}

dbconn.Close();
this.Close(); // Close the window after the deletion. Necessary to update the form's values, otherwise the changes won't
// be apparent to the user.
}

private void btnspUpdate_Click(object sender, EventArgs e) // Our update button.
{
string takeStudentFirstName = txtspFirstName.Text; // We are going to take whatever values the user inputs into these
string takeStudentSurname = txtspSurname.Text; // textboxes and then submit them for update!
string takeStudentCourse = txtspCourse.Text;
string takeCourseID = txtCourseIDgo.Text;

SqlConnection dbconn = new SqlConnection(connectionString); // Prepare and open connection.

try
{
dbconn.Open();
}
catch
{
MessageBox.Show("Connection to database failed. Please check and try again.");
}

try
{
SqlCommand sqlCom = new SqlCommand("UPDATE StudentInfo SET StudentFirstName ='" + takeStudentFirstName + "', StudentSurname ='" + takeStudentSurname + "', CourseID ='" + takeCourseID + "'WHERE StudentID = " + combospStudentID.Text, dbconn);
sqlCom.ExecuteNonQuery();
// A simple update. Replaces the database values in a row relevant to our selected Student ID. Notice that we don't want
// the user editing/updating CourseName because they could write any old thing in there! CourseName is explicitly linked to
// CourseID and we only want someone to change a Course Name when they go to the appropriate Course Details page. This prevents
// the user from thinking that in order to change the course of a student he can just edit in any old thing on the Student Page
// without adhearing to any formatting standards or realising that an associated Course ID is required for database function.

}
catch
{
MessageBox.Show("Please check your input. Course ID must be a valid Course ID. Refer to Course Page for more information.");
} // Damn right you will check your input.

dbconn.Close();
}
}
}
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
Poopi
Profile Blog Joined November 2010
France13003 Posts
December 10 2012 16:16 GMT
#4249
On December 11 2012 00:54 neSix wrote:
Show nested quote +
On December 10 2012 09:19 Poopi wrote:
Hey guys.
So I just finished a project (well there is this problem so it's not literally finished) in PHP with some mySQL.
However I had a problem with a basic search bar. It won't matter since I already sent my project, with the problem, because of the deadline, but my curiosity wants to know what was the solution for this problem. I could not really find the right key words on google so here I ask you if you can help me.

So I want the request to search in a precised table the word typed, but I want it to only show the results from this table associated with the current userid.
Here is my request showing it but for every id :
SELECT * FROM products WHERE name LIKE '%$search%' ORDER BY name

(not sure about the syntax Im on mobile don't have access to the files).
I would like something like that instead :
SELECT * FROM products WHERE fournid='$fournid' AND name LIKE  etc

$search the $_post of the searchbar and $fournid the $_cookie['userid'] of the current user.
Problem this request won't work and I know it but I don't know how I'm supposed to do it.

Any ideas?
Thanks in advance.


Well, right off the bat I noticed that you're using quotes to compare the value in the fournid column... the fact that it ends with id suggests to me that this is actually an integer field and thus you shouldn't be using quotes.

Other than that, both queries looks fine to me. It's impossible to say what is going wrong without knowing the schema of your tables. I think it's worth noting that while I of course don't know anything about your problem domain, the notion of having a "user id" column on a product table suggests something grossly incorrect with your design...

There is no userid in the product table. There is a fournid and in my request it corresponds to the userid because this fournid is in this case = to the userid. Basically it's a search bar of a "supplier" (fournissor?) and it's supposed to only show his products.

By the way yeah the second request works LOL.
Maybe I inversed the AND the first time, I don't know, the fact that yesterday I was almost only programming maybe prevented me from thinking calmly and clearly, and since I wrote the second request maybe 2 or 3 hours after stopping the work it was easier to get it right.

Too bad I could not send my project with this search bar working right T;T.
WriterMaru
supereddie
Profile Joined March 2011
Netherlands151 Posts
Last Edited: 2012-12-10 18:15:04
December 10 2012 18:13 GMT
#4250
Please, please learn how to use parameterized queries when using any database. That is much safer against SQL injection.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
3FFA
Profile Blog Joined February 2010
United States3931 Posts
December 10 2012 21:57 GMT
#4251
Guys is there a more efficient way to do this?

The assignment(I just completed as shown) is to use single for loop(s) to:

User inputs a number from 1-15
I check the input and output the result in the form of "*" 's so if the user inputs 5 the program outputs ***** (in a row as shown)

I would like to know if there is a more efficient way to do this since this felt a bit too repetitive (especially since the for loops were just copy + paste + change 1 number over and over again)...
+ Show Spoiler +


#include <stdio.h>

int main(int argc, const char * argv[])
{
//declare variables
int num; //number entered by user

//user input
printf("Please input an integer between 1 and 15: ");
scanf("%i",& num);


//check input and output result
for (num == 1; num > 0; num--)
{
printf("*");
}
for (num == 2; num > 0; num--)
{
printf("*");
}

for (num == 3; num > 0; num--)
{
printf("*");
}
for (num == 4; num > 0; num--)
{
printf("*");
}
for (num == 5; num > 0; num--)
{
printf("*");
}
for (num == 6; num > 0; num--)
{
printf("*");
}
for (num == 7; num > 0; num--)
{
printf("*");
}
for (num == 8; num > 0; num--)
{
printf("*");
}
for (num == 9; num > 0; num--)
{
printf("*");
}
for (num == 10; num > 0; num--)
{
printf("*");
}
for (num == 11; num > 0; num--)
{
printf("*");
}
for (num == 12; num > 0; num--)
{
printf("*");
}
for (num == 13; num > 0; num--)
{
printf("*");
}
for (num == 14; num > 0; num--)
{
printf("*");
}
for (num == 15; num > 0; num--)
{
printf("*");
}
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
December 10 2012 22:05 GMT
#4252
I'm so pissed right now. I've aced everything in my Python class all year. The last week I've done a lot of coding, and I tried to do two earlier exams, and got EVERYTHING right on both of them(this is the first time I've ever gotten everything right on an exam). But today everything have been shitty, I've forgot a lot of syntax, and my brain just don't work, and my exam is tomorrow Hope I just had a bad day.
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-12-10 22:07:52
December 10 2012 22:06 GMT
#4253
On December 11 2012 06:57 3FFA wrote:
Guys is there a more efficient way to do this?


+ Show Spoiler [yes] +
#include <stdio.h>

int main( void )
{
//declare variables
int num; //number entered by user

//user input
printf("Please input an integer between 1 and 15: ");
scanf("%i", &num);


//check input and output result
for (; num > 0; num--)
{
printf("*");
}
}


GwSC
Profile Joined December 2010
United States1997 Posts
December 10 2012 22:07 GMT
#4254
On December 11 2012 06:57 3FFA wrote:
Guys is there a more efficient way to do this?

The assignment(I just completed as shown) is to use single for loop(s) to:

User inputs a number from 1-15
I check the input and output the result in the form of "*" 's so if the user inputs 5 the program outputs ***** (in a row as shown)

I would like to know if there is a more efficient way to do this since this felt a bit too repetitive (especially since the for loops were just copy + paste + change 1 number over and over again)...
+ Show Spoiler +


#include <stdio.h>

int main(int argc, const char * argv[]
{
//declare variables
int num; //number entered by user

//user input
printf("Please input an integer between 1 and 15: ");
scanf("%i",& num);


//check input and output result
for (num == 1; num > 0; num--)
{
printf("*");
}
for (num == 2; num > 0; num--)
{
printf("*");
}

for (num == 3; num > 0; num--)
{
printf("*");
}
for (num == 4; num > 0; num--)
{
printf("*");
}
for (num == 5; num > 0; num--)
{
printf("*");
}
for (num == 6; num > 0; num--)
{
printf("*");
}
for (num == 7; num > 0; num--)
{
printf("*");
}
for (num == 8; num > 0; num--)
{
printf("*");
}
for (num == 9; num > 0; num--)
{
printf("*");
}
for (num == 10; num > 0; num--)
{
printf("*");
}
for (num == 11; num > 0; num--)
{
printf("*");
}
for (num == 12; num > 0; num--)
{
printf("*");
}
for (num == 13; num > 0; num--)
{
printf("*");
}
for (num == 14; num > 0; num--)
{
printf("*");
}
for (num == 15; num > 0; num--)
{
printf("*");
}


Maybe just declare an int stars, then make a loop
for ( stars == 0; stars < num; stars ++ )
supereddie
Profile Joined March 2011
Netherlands151 Posts
December 10 2012 22:08 GMT
#4255
On December 11 2012 06:57 3FFA wrote:
Guys is there a more efficient way to do this?

The assignment(I just completed as shown) is to use single for loop(s) to:

User inputs a number from 1-15
I check the input and output the result in the form of "*" 's so if the user inputs 5 the program outputs ***** (in a row as shown)

I would like to know if there is a more efficient way to do this since this felt a bit too repetitive (especially since the for loops were just copy + paste + change 1 number over and over again)...
+ Show Spoiler +


#include <stdio.h>

int main(int argc, const char * argv[]
{
//declare variables
int num; //number entered by user

//user input
printf("Please input an integer between 1 and 15: ");
scanf("%i",& num);


//check input and output result
for (num == 1; num > 0; num--)
{
printf("*");
}
for (num == 2; num > 0; num--)
{
printf("*");
}

for (num == 3; num > 0; num--)
{
printf("*");
}
for (num == 4; num > 0; num--)
{
printf("*");
}
for (num == 5; num > 0; num--)
{
printf("*");
}
for (num == 6; num > 0; num--)
{
printf("*");
}
for (num == 7; num > 0; num--)
{
printf("*");
}
for (num == 8; num > 0; num--)
{
printf("*");
}
for (num == 9; num > 0; num--)
{
printf("*");
}
for (num == 10; num > 0; num--)
{
printf("*");
}
for (num == 11; num > 0; num--)
{
printf("*");
}
for (num == 12; num > 0; num--)
{
printf("*");
}
for (num == 13; num > 0; num--)
{
printf("*");
}
for (num == 14; num > 0; num--)
{
printf("*");
}
for (num == 15; num > 0; num--)
{
printf("*");
}

Use the input the as the upper bound
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
December 10 2012 22:32 GMT
#4256
On December 11 2012 07:07 GwSC wrote:
Show nested quote +
On December 11 2012 06:57 3FFA wrote:
Guys is there a more efficient way to do this?

The assignment(I just completed as shown) is to use single for loop(s) to:

User inputs a number from 1-15
I check the input and output the result in the form of "*" 's so if the user inputs 5 the program outputs ***** (in a row as shown)

I would like to know if there is a more efficient way to do this since this felt a bit too repetitive (especially since the for loops were just copy + paste + change 1 number over and over again)...
+ Show Spoiler +


#include <stdio.h>

int main(int argc, const char * argv[]
{
//declare variables
int num; //number entered by user

//user input
printf("Please input an integer between 1 and 15: ");
scanf("%i",& num);


//check input and output result
for (num == 1; num > 0; num--)
{
printf("*");
}
for (num == 2; num > 0; num--)
{
printf("*");
}

for (num == 3; num > 0; num--)
{
printf("*");
}
for (num == 4; num > 0; num--)
{
printf("*");
}
for (num == 5; num > 0; num--)
{
printf("*");
}
for (num == 6; num > 0; num--)
{
printf("*");
}
for (num == 7; num > 0; num--)
{
printf("*");
}
for (num == 8; num > 0; num--)
{
printf("*");
}
for (num == 9; num > 0; num--)
{
printf("*");
}
for (num == 10; num > 0; num--)
{
printf("*");
}
for (num == 11; num > 0; num--)
{
printf("*");
}
for (num == 12; num > 0; num--)
{
printf("*");
}
for (num == 13; num > 0; num--)
{
printf("*");
}
for (num == 14; num > 0; num--)
{
printf("*");
}
for (num == 15; num > 0; num--)
{
printf("*");
}


Maybe just declare an int stars, then make a loop
for ( stars == 0; stars < num; stars ++ )


Careful there, you want the assignment operator, =, not the equivalence operator, ==.

Do you get bonus points if you do this with 0 loops using regex? j/k, don't do that. Seriously, don't.
Any sufficiently advanced technology is indistinguishable from magic
iaretehnoob
Profile Joined June 2004
Sweden741 Posts
December 10 2012 23:09 GMT
#4257
On December 11 2012 06:57 3FFA wrote:
Guys is there a more efficient way to do this?

The assignment(I just completed as shown) is to use single for loop(s) to:

User inputs a number from 1-15
I check the input and output the result in the form of "*" 's so if the user inputs 5 the program outputs ***** (in a row as shown)

I would like to know if there is a more efficient way to do this since this felt a bit too repetitive (especially since the for loops were just copy + paste + change 1 number over and over again)...
+ Show Spoiler +


#include <stdio.h>

int main(int argc, const char * argv[]
{
//declare variables
int num; //number entered by user

//user input
printf("Please input an integer between 1 and 15: ");
scanf("%i",& num);


//check input and output result
for (num == 1; num > 0; num--)
{
printf("*");
}
for (num == 2; num > 0; num--)
{
printf("*");
}

for (num == 3; num > 0; num--)
{
printf("*");
}
for (num == 4; num > 0; num--)
{
printf("*");
}
for (num == 5; num > 0; num--)
{
printf("*");
}
for (num == 6; num > 0; num--)
{
printf("*");
}
for (num == 7; num > 0; num--)
{
printf("*");
}
for (num == 8; num > 0; num--)
{
printf("*");
}
for (num == 9; num > 0; num--)
{
printf("*");
}
for (num == 10; num > 0; num--)
{
printf("*");
}
for (num == 11; num > 0; num--)
{
printf("*");
}
for (num == 12; num > 0; num--)
{
printf("*");
}
for (num == 13; num > 0; num--)
{
printf("*");
}
for (num == 14; num > 0; num--)
{
printf("*");
}
for (num == 15; num > 0; num--)
{
printf("*");
}

This would also work if you removed all but any one of these loops. By coincidence I guess. Read up on assignment operators vs equality operators again and see if you can figure out what happens.
SgtCoDFish
Profile Blog Joined July 2010
United Kingdom1520 Posts
December 10 2012 23:11 GMT
#4258
On December 11 2012 06:57 3FFA wrote:
Guys is there a more efficient way to do this?

The assignment(I just completed as shown) is to use single for loop(s) to:

User inputs a number from 1-15
I check the input and output the result in the form of "*" 's so if the user inputs 5 the program outputs ***** (in a row as shown)

I would like to know if there is a more efficient way to do this since this felt a bit too repetitive (especially since the for loops were just copy + paste + change 1 number over and over again)...
+ Show Spoiler +


#include <stdio.h>

int main(int argc, const char * argv[]
{
//declare variables
int num; //number entered by user

//user input
printf("Please input an integer between 1 and 15: ");
scanf("%i",& num);


//check input and output result
for (num == 1; num > 0; num--)
{
printf("*");
}
for (num == 2; num > 0; num--)
{
printf("*");
}

for (num == 3; num > 0; num--)
{
printf("*");
}
for (num == 4; num > 0; num--)
{
printf("*");
}
for (num == 5; num > 0; num--)
{
printf("*");
}
for (num == 6; num > 0; num--)
{
printf("*");
}
for (num == 7; num > 0; num--)
{
printf("*");
}
for (num == 8; num > 0; num--)
{
printf("*");
}
for (num == 9; num > 0; num--)
{
printf("*");
}
for (num == 10; num > 0; num--)
{
printf("*");
}
for (num == 11; num > 0; num--)
{
printf("*");
}
for (num == 12; num > 0; num--)
{
printf("*");
}
for (num == 13; num > 0; num--)
{
printf("*");
}
for (num == 14; num > 0; num--)
{
printf("*");
}
for (num == 15; num > 0; num--)
{
printf("*");
}


As people above pointed out, yes, you do it with a simple, single loop. But since the code you wrote would imply that you're a beginner, here are a couple of super helpful tips for the future.

1) Generally, if you find yourself doing a similar action over and over with little change, or a measurable change, you should be doing it in a loop. Every time you copy paste something, you should double check to make sure you changed everything that needed to be changed, and that you actually need to be copy pasting in the first place. In this case, you do it with one for loop and using num as the bound. Always watch out for this simplification.

2) Don't trust the user to input a number. Users are idiots. Check what they input to make sure it's within sensible bounds, in this case 1 <= num <= 15. You can use a do { input; } while(num <= 1 || num >= 15); loop to force them to input a correct number, or just spit an error out and quit if they don't do it right.

3) As above, be careful with assignment and the difference between = and ==.
3FFA
Profile Blog Joined February 2010
United States3931 Posts
Last Edited: 2012-12-10 23:21:51
December 10 2012 23:18 GMT
#4259
Thank you so much guys! This was amazingly helpful to me. :D

edit especially Mr.Fish above! You made me realize I forgot to check that the user wasn't stupid >.>;; while teaching a few things!
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Kich
Profile Joined April 2011
United States339 Posts
Last Edited: 2012-12-10 23:27:10
December 10 2012 23:26 GMT
#4260
On December 11 2012 06:57 3FFA wrote:
Guys is there a more efficient way to do this?

The assignment(I just completed as shown) is to use single for loop(s) to:

User inputs a number from 1-15
I check the input and output the result in the form of "*" 's so if the user inputs 5 the program outputs ***** (in a row as shown)

I would like to know if there is a more efficient way to do this since this felt a bit too repetitive (especially since the for loops were just copy + paste + change 1 number over and over again)...
+ Show Spoiler +


#include <stdio.h>

int main(int argc, const char * argv[]
{
//declare variables
int num; //number entered by user

//user input
printf("Please input an integer between 1 and 15: ");
scanf("%i",& num);


//check input and output result
for (num == 1; num > 0; num--)
{
printf("*");
}
for (num == 2; num > 0; num--)
{
printf("*");
}

for (num == 3; num > 0; num--)
{
printf("*");
}
for (num == 4; num > 0; num--)
{
printf("*");
}
for (num == 5; num > 0; num--)
{
printf("*");
}
for (num == 6; num > 0; num--)
{
printf("*");
}
for (num == 7; num > 0; num--)
{
printf("*");
}
for (num == 8; num > 0; num--)
{
printf("*");
}
for (num == 9; num > 0; num--)
{
printf("*");
}
for (num == 10; num > 0; num--)
{
printf("*");
}
for (num == 11; num > 0; num--)
{
printf("*");
}
for (num == 12; num > 0; num--)
{
printf("*");
}
for (num == 13; num > 0; num--)
{
printf("*");
}
for (num == 14; num > 0; num--)
{
printf("*");
}
for (num == 15; num > 0; num--)
{
printf("*");
}


Ah, covered above.. *ediT*
Prev 1 211 212 213 214 215 1032 Next
Please log in or register to reply.
Live Events Refresh
CrankTV Team League
11:00
Crank Gathers S4: Group Stage
LiquipediaDiscussion
Replay Cast
09:00
KungFu Cup 2026 Week 14
CranKy Ducklings118
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko355
SortOf 152
DenverSC2 43
StarCraft: Brood War
Calm 8692
Sea 1683
Horang2 620
Bisu 510
Jaedong 457
BeSt 391
EffOrt 326
Soma 207
Mini 185
Snow 183
[ Show more ]
Zeus 176
actioN 149
Light 144
Last 125
Soulkey 115
JYJ 62
Larva 61
Pusan 50
ToSsGirL 50
Rush 50
Killer 35
hero 34
Sea.KH 34
sorry 30
Sharp 28
JulyZerg 28
Sexy 25
Bale 18
Barracks 15
Yoon 14
ajuk12(nOOB) 13
HiyA 12
Sacsri 11
IntoTheRainbow 4
Dota 2
Gorgc5639
XcaliburYe98
League of Legends
Doublelift2060
Counter-Strike
markeloff74
Other Games
singsing910
B2W.Neo422
crisheroes305
DeMusliM222
Happy146
OGKoka 142
Sick137
XaKoH 136
Organizations
Other Games
gamesdonequick2456
StarCraft: Brood War
Kim Chul Min (afreeca) 1082
Other Games
BasetradeTV169
StarCraft: Brood War
UltimateBattle 71
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• CranKy Ducklings SOOP108
• StrangeGG 65
• Adnapsc2 11
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos2239
Upcoming Events
WardiTV Qualifier
2m
WardiTV80
Replay Cast
21h 2m
CrankTV Team League
23h 2m
WardiTV Qualifier
1d
Epic.LAN
1d 1h
Replay Cast
1d 12h
RSL Revival
1d 21h
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
1d 22h
Epic.LAN
2 days
IPSL
2 days
Dragon vs Hawk
[ Show More ]
RSL Revival
2 days
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
2 days
IPSL
3 days
Bonyth vs Ret
WardiTV Weekly
3 days
Monday Night Weeklies
4 days
PiGosaur Cup
5 days
The PondCast
5 days
Replay Cast
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Proleague 2026-07-13
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026

Upcoming

Escore Tournament S3: W3
ASL S22 SEASON OPEN Day 1
Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.