r/CodingHelp

Need Help Understanding 'For Loop' in Pseudocode For Class Project

I'm in an Intro to Computer Science class and am doing our current project which is to make a text based game where you and a computer keep on adding numbers from 1-10 and the winner is decided by who reaches 100 first.

We did this project before already but now we're redoing it by changing all of it to be definitions and then they want us to add a 'for loop' into it as well. The problem is, is that the for loop makes no sense to me, at least from a gameplay stand point. From my understanding, all its doing is adding +1 to the total whenever the computer goes?

I was just hoping if someone could help me decipher this, thanks!

#This is the psuedocode#

Import random

FUNCTION 1: DISPLAY RULES
Declare Function display_rules
Say "Let's play a game of 100!"
Say "In a game of 100 we start with a total of 0"
Say "and we take turns adding from 1-10 to that total."
Say "Whoever reaches 100 first wins."
Say "Ready?"

FUNCTION 2: PLAY GAME
Declare Function play_game
Set play to 1
Call display_rules

While play is 1
Set total to 0
Ask "Who goes first? (1 = you, 2 = computer): "
Read turn

While total is less than 100

If turn is 1 (player's turn)
Ask "Number you want to add (1-10): "
Read playerNum

If playerNum is between 1 and 10
AND total + playerNum is less than or equal to 100
Add playerNum to total
Say "You added [playerNum], total is now [total]"
Set turn to 2
Else
Say "Enter a number from 1-10 without exceeding 100."

Else If turn is 2 (computer's turn)
If total is less than 90
Set computerNum to a random number from 1 to 10
Else
Set computerNum to 100 - total

FOR LOOP
For num from 0 to computerNum - 1
Add 1 to total
End For

Say "I added [computerNum], total is now [total]"
Set turn to 1

Else
Say "Choose 1 or 2."
Ask "Who goes first? "
Read turn

End While

CHECK WHO WINS
If turn is 2
Say "You win!"
Else
Say "Bummer, You lose!"

ASK TO PLAY AGAIN
Ask "Play again? (1 = yes, 2 = no): "
Read play

End While

FUNCTION 3: MAIN MENU
Declare Function menu
While True
Show the menu
Say "Menu:"
Say "1. Display Rules"
Say "2. Play Game"
Say "3. Exit"

Ask "Enter your choice (1, 2, or 3): "
Read choice

If choice is 1
Call display_rules
Else If choice is 2
Call play_game
Else If choice is 3
Say "Thanks for playing! Goodbye!"
Break the loop
Else
Say "Invalid choice. Please enter 1, 2, or 3."

End While

START PROGRAM
Call menu

reddit.com
u/RyanTriggers — 10 days ago

This Sucks… Alot. Please Help.

Hello everyone. Gather round', gather round' and listen to my tale. So I'm trying to code an incremental game for laptop, computer, and mobile, but's it's been s really huge pain in my sore little keister. Everything confuses me, and I only know a little bit of coding. I'm currently using a simple coding website kind of similar to Scratch (I forgot the name, I'll check later.) on my laptop. On top of that, I keep getting demotivated really quickly and tired, telling myself I'll work on it tomorrow but never do. Please help!… Thank you!!

reddit.com
u/PandorasToolbox — 11 days ago

Class instance while running the code

I started actually writing code with OOP yesterday (using Dart... In case it is necessary to mention) and there's a thing that kept bothering me as I scrolled through their page and watched the tutorial. Everytime they gave a class example, they created an instance themselves and never based on the code running.

Imagine a system to simulate a store's stock. There'll be items going in and out, that shouldn't be inserted by the programmer, so there must be a way to do that "dynamically".

I'm aware that this might be me simply missing something from OOP classes, but I want to see what other coders have to say about that.

Any help would be welcome. Thank You

reddit.com
u/LeoPixel11 — 11 days ago

Web/app developer or Roblox game development which is better for side hustle

I'm starting from zero and want to build a long-term income from development. I have limited money.

I'm choosing between two paths:

App development: Mac or web apps. Higher profit per sale, but I'd need to learn Swift or web development and find a niche problem to solve.

Game development: Roblox or indie games. Easier to launch, but I've read that most games earn very little and platforms take a big cut.

I plan to use AI to speed up the learning and the building.

My question: If you were starting from zero today, would you pick app development or game development to make money, and why? If you've done either, how long did it take to earn your first dollar?

reddit.com
u/Historical_Case9337 — 11 days ago

I want a programing buddy so we can help motivate each other

I don't care if you have a PhD or you code for fun; I just want to have someone who can code with me or just hang out and talk to keep me focused because I get distracted constantly. I'm no master, but I'm working on my associate's and am pretty out of steam.

I don't care about gender, age, or race, just someone who is chill and respectful. I'm happy to code with you or just watch, and we can chat on Discord or something. I'm also willing to hang out and do something else if you're burnt out or stressed.

I'm 19m btw

reddit.com
u/Suvile77 — 10 days ago
▲ 3 r/CodingHelp+1 crossposts

Mic Detection Help

Hey guys, I've been working on an app and one of It's features is to detect piano chords and notes through the mic. I tried a couple of things, but they all resulted in some drawback that could affect performance. The two things I am aiming for is speed and accuracy. Here's what I tried and why It's didn't feel satisfied with it.

I won't mention the app to respect the No Marketing rule, but will provide context if I felt it was necessary.

  1. Spotify's Basic Pitch Open Source detector: While the accuracy was very high, it took around half a second to detect notes.

Here's some context for the next thing I tried. My app is basically a sheet music practice app, in which notes are displayed from an uploaded score or the score repository. Target notes must be played to move on to the next notes.

  1. Probabilities + FFT and YIN:

Basically, I set the chances for the right notes to be played to a high degree, and matched it with FFT inputs if multiple notes were played, and YIN if a single note was played (For accuracy). However, while the speed was heavily increased, the accuracy diminished, however, it was still pretty accurate. Most commonly, if an expected note is played, the detector sometimes recognizes the correct note being played, as well as the note an octave under it.

I want some advice about what I could try next to build this detector. I'm aiming for a lag of under 200ms.

I am okay with starting from scratch, or trying a new method.

reddit.com
u/Usual-Emphasis-1950 — 13 days ago