+ 1

Replace "*" with a sequence of "R, G, B" in C# "Making a Pyramid"

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void DrawPyramid(int n) { for (int i=1; i<=n; i++) { for (int j=i; j<=n; j++) { Console.Write(" "); } for (int k=1; k<=2*i-1; k++) { Console.Write("*"+" "); } Console.WriteLine(); } } static void Main(string[] args) { DrawPyramid(5); } } } This is the code from "Making a Pyramid" in the C# tutorial. I want to hack it so that instead of printing "*" to draw the pyramid, it prints the characters R, G, and B in sequence to the defined DrawPyramid integer. I've had the idea to either make a method that replaces all instances of "*", and tried making a class called RedGreenBlue that would be defined by what the previous char is. This is only my second day trying to learn programming and I really wana figure this out but everything I do blasts my IDE with red circles. Please help!

17th Oct 2017, 11:22 PM
Andrew Straub
Andrew Straub - avatar
11 Réponses
+ 8
Why it says "Not all code paths return a value" is because it's looking for the "return" keyword. You're not returning, you're assigning to a class variable. Also, the ifs aren't causing a loop. Since SwitchChar() isn't returning a value, it should be: static void SwitchChar()
18th Oct 2017, 6:05 PM
Tamra
Tamra - avatar
+ 9
No need for another class! You could make a class variable that stores the next character to print out. Then, use a method to switch what character it stores. class Program { static char nextChar = 'R'; //Main() //PrintPyramid() //Change the output: Console.Write(nextChar + " "); //Add this line right after it: SwitchChar(); static void SwitchChar() //This method cycles out characters { if (nextChar == 'R') nextChar = 'G'; else if (nextChar == 'G') nextChar = 'B'; else nextChar = 'R'; } }
18th Oct 2017, 12:42 AM
Tamra
Tamra - avatar
+ 9
Whoops, thanks. Fixed it! :D
18th Oct 2017, 4:36 AM
Tamra
Tamra - avatar
+ 4
All right in the previous solution ☺. Just a little typo: nextChar is a class variable so it should be defined static.
18th Oct 2017, 4:35 AM
Ludovico Iommi
Ludovico Iommi - avatar
0
..\Playground\(28,21): error CS0161: 'Program.SwitchChar()': not all code paths return a value using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static char nextChar = 'G'; static void DrawPyramid(int n) { for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { Console.Write(" "); } for (int k = 1; k <= 2 * i - 1; k++) { Console.Write(nextChar + " "); SwitchChar(); } Console.WriteLine(); } } static char SwitchChar() { if (nextChar == 'R') nextChar = 'G'; else if (nextChar == 'G') nextChar = 'B'; else if (nextChar == 'B') nextChar = 'R'; } static void Main(string[] args) { DrawPyramid(15); } } } I think I see what's happening here. SwitchChar() is always cycling through the statement and won't return a valid value because when "else nextChar ='R';", (nextChar == 'R') bools true again. How do we break the loop every time we print nextChar?
18th Oct 2017, 8:40 AM
Andrew Straub
Andrew Straub - avatar
0
Bitcoin and other cryptocurrencies have turned into a pretty valuable digital asset for a lot of people globally. But the fear of losing access to these digital funds is a big worry. That's where companies like METATECH RECOVERY PRO come in, using their super-smart analysis tools to give folks a fighting chance if they've lost their Bitcoins. METATECH RECOVERY PRO is a top-notch service that specializes in getting back lost cryptocurrency, especially when it comes to finding and recovering lost Bitcoins. Their super-detailed analysis tools are key to their success, giving them the precision and know-how needed in the complicated world of digital money. METATECH RECOVERY PRO offers a bunch of services to help people get back their lost or inaccessible cryptocurrencies. Their team of experts uses advanced analysis tools to give quick and effective solutions that are customized for each person. When it comes to getting back cryptocurrency, analysis tools are super important for tracking transactions, spotting patterns, and getting back lost funds.These techniques help them get the best results for their clients and speed up the recovery process. METATECH RECOVERY PRO works with experienced blockchain experts who know their stuff about cryptocurrency protocols and technologies. By combining their expertise with advanced analysis tools, METATECH RECOVERY PRO can offer complete solutions that handle even the toughest cases of lost Bitcoin recovery. There was a time when getting back Bitcoin was like a dream, but thanks to dedicated teams like METATECH RECOVERY PRO, that's changing. With a focus on being more precise and efficient, the days of lost Bitcoins being gone forever might be over soon. Connect with META TECH RECOVERY PRO on all platforms or for help via: W/A ‪‪‪+1 469-692‑8049‬‬‬ ‪https://metatech-recoverypro.com‬ Metatech@Writeme.Com Thank you.
21st Jul 2025, 8:14 AM
winston carol
0
HIRE THE BEST BITCOIN RECOVERY EXPERT; TRACK AND RECOVER LOST CRYPTOCURRENCY WITH META TECH RECOVERY PRO Bitcoin and other cryptocurrencies have turned into a pretty valuable digital asset for a lot of people globally. But the fear of losing access to these digital funds is a big worry. That's where companies like METATECH RECOVERY PRO come in, using their super-smart analysis tools to give folks a fighting chance if they've lost their Bitcoins. METATECH RECOVERY PRO is a top-notch service that specializes in getting back lost cryptocurrency, especially when it comes to finding and recovering lost Bitcoins. Their super-detailed analysis tools are key to their success, giving them the precision and know-how needed in the complicated world of digital money. METATECH RECOVERY PRO offers a bunch of services to help people get back their lost or inaccessible cryptocurrencies. Their team of experts uses advanced analysis tools to give quick and effective solutions that are customized for each person. When it comes to getting back cryptocurrency, analysis tools are super important for tracking transactions, spotting patterns, and getting back lost funds.These techniques help them get the best results for their clients and speed up the recovery process. METATECH RECOVERY PRO works with experienced blockchain experts who know their stuff about cryptocurrency protocols and technologies. By combining their expertise with advanced analysis tools, METATECH RECOVERY PRO can offer complete solutions that handle even the toughest cases of lost Bitcoin recovery. There was a time when getting back Bitcoin was like a dream, but thanks to dedicated teams like METATECH RECOVERY PRO, that's changing. With a focus on being more precise and efficient, the days of lost Bitcoins being gone forever might be over soon. Connect with META TECH RECOVERY PRO on all platforms or for help via: W/A ‪‪‪+1 469-692‑8049‬‬‬ ‪https://metatech-recoverypro.com‬ Metatech@Writeme.Com Thank you.
21st Jul 2025, 9:06 AM
winston carol
0
My cryptocurrency was stolen; how can I get it back? Contact CAPTAIN JACK RECOVERY One of the most common questions after someone's assets have been stolen is whether there's any chance of recovering the funds. I had a similar experience earlier this year. I blindly invested in cryptocurrency trading, putting $380,000 into a website called Novatech, which promised high returns. But then they stopped processing all withdrawal requests, and the scam eventually came to light. I started looking for professional cryptocurrency asset recovery services. On YouTube and Quora, I found Montgomery Elite, experts in decentralized finance. Fortunately, they helped me recover my initial investment of $320,700. If you've also been a victim of a similar scam, please contact: Website: https://realcaptainjack.wixsite.com/crypto-recovery / Telegram: @realcaptainjack / WS +491 5782 317 112
7th Oct 2025, 4:37 AM
Anthony Jack
Anthony Jack - avatar
0
CONTACT A LEGITIMATE CRYPTOCURRENCY RECOVERY SPECIALISTS / iFORCE HACKER RECOVERY I recently became a victim of a cryptocurrency investment scam, losing a substantial amount of my digital assets. Thankfully, I found iForce Hacker Recovery, a trusted firm specializing in crypto recovery. Their expert team guided me through a detailed recovery process, using advanced tools to trace and recover my lost funds. Through their professionalism and commitment, I was able to regain a significant portion of my assets. I highly recommend iForce Hacker Recovery to anyone facing similar losses. Their expertise truly restores hope after financial setbacks. Contact iForce Hacker Recovery: Email: iforcehk @ consultant . co m WhatsApp: +1 (240) 803-3706 Website: ht tps:// iforcehackers . co m
20th Oct 2025, 9:05 PM
Cherie Stark
Cherie Stark - avatar
0
God bless Capital Crypto Recover Services for the marvelous work you did in my life, I have learned the hard way that even the most sensible investors can fall victim to scams. When my USD was stolen, for anyone who has fallen victim to one of the bitcoin binary investment scams that are currently ongoing, I felt betrayal and upset. But then I was reading a post on site when I saw a testimony of Wendy Taylor online who recommended that Capital Crypto Recovery has helped her recover scammed funds within 24 hours. after reaching out to this cyber security firm that was able to help me recover my stolen digital assets and bitcoin. I’m genuinely blown away by their amazing service and professionalism. I never imagined I’d be able to get my money back until I complained to Capital Crypto Recovery Services about my difficulties and gave all of the necessary paperwork. I was astounded that it took them 12 hours to reclaim my stolen money back. Without a doubt, my USDT assets were successfully recovered from the scam platform, Thank you so much Sir, I strongly recommend Capital Crypto Recover for any of your bitcoin recovery, digital funds recovery, hacking, and cybersecurity concerns. You reach them Call/Text Number +1 (336)390-6684 His Email: Capitalcryptorecover@zohomail.com Contact Telegram: @Capitalcryptorecover Via Contact: Recoverycapital@fastservice.com
1st Nov 2025, 1:22 AM
Elizabeth Rush
Elizabeth Rush - avatar
0
God bless Capital Crypto Recover Services for the marvelous work you did in my life, I have learned the hard way that even the most sensible investors can fall victim to scams. When my USD was stolen, for anyone who has fallen victim to one of the bitcoin binary investment scams that are currently ongoing, I felt betrayal and upset. But then I was reading a post on site when I saw a testimony of Wendy Taylor online who recommended that Capital Crypto Recovery has helped her recover scammed funds within 24 hours. after reaching out to this cyber security firm that was able to help me recover my stolen digital assets and bitcoin. I’m genuinely blown away by their amazing service and professionalism. I never imagined I’d be able to get my money back until I complained to Capital Crypto Recovery Services about my difficulties and gave all of the necessary paperwork. I was astounded that it took them 12 hours to reclaim my stolen money back. Without a doubt, my USDT assets were successfully recovered from the scam platform, Thank you so much Sir, I strongly recommend Capital Crypto Recover for any of your bitcoin recovery, digital funds recovery, hacking, and cybersecurity concerns. You reach them Call/Text Number +1 (336)390-6684 His Email: Capitalcryptorecover@zohomail.com Contact Telegram: @Capitalcryptorecover Via Contact: Recoverycapital@fastservice.com His website: https://recovercapital.wixsite.com/capital-crypto-rec-1
1st Nov 2025, 1:23 AM
Elizabeth Rush
Elizabeth Rush - avatar