doesn't want to run code?

Sajo

Member
Joined
Jul 22, 2020
Messages
17
Programming Experience
Beginner
Hello everybody! I am beginner in C# and i have problem with my code.
I don't see where is the problem but it doesn't want to run code. Please can you help me?
C#:
using System;
using System.Threading;

namespace Sajo_vježba
{
    class Program
    {
        static void Main(string[] args)
        {
            int starost = 16;
            string ime = " Safet ";
            bool punoljetan = false;
            Console.WriteLine(ime + " ima " + starost + " godina ");
            Console.WriteLine(punoljetan);
            Console.WriteLine(" Klikni enter za nastavak programa ");
            Console.ReadLine();
            //nešto novo
            starost = 18;
            punoljetan = true;
            Console.WriteLine(" Dve godine kasnije, "  ime + " ima " + starost "godina");
            Console.WriteLine(" punoljetan: " + punoljetan);
            Console.ReadLine();
        }
        
    }
}
 
Last edited by a moderator:
Code doesn't just not run. It may not produce the result you intend but it will still do something. You need to explain EXACTLY what actually does happen. If you haven't already, you need to use the debugger that is built into VS for the purpose. Set a breakpoint, step through the code line by line and examine the state of the app at each step. You presumably know what you expect to happen at each line of code so examine the code as it runs to see if it does that. If it doesn't, take the time and make the effort to explain to us not only what actually happens but also what it was you expected. We shouldn't have to work that out from code that doesn't do it.
 
For the record, a compilation error isn't "just not running" either. The compiler tells you exactly what the issue is and where so that you can address that issue. If you want others to help you address the issue, you need to pass on the information that the IDE gives you.
 
The compiler tells you exactly what the issue is and where so that you can address that issue. If you want others to help you address the issue, you need to pass on the information that the IDE gives you.
We are in completely different times these days. Most people who are getting into programming are googling their way through every scenario/problem/exam and hiccup they hit. And most people don't even know the correct way to use an IDE let alone read error reports generated to them. Most people don't even know how to do what you've asked. And that's the sad realisation of what the next generation of programmers will be like to work with. The last company I was with before my current was full of people who lied through their interview. Upon asking them to undertake a task. The response I got used to hearing was; I will google how to do that now, really sorry...

In this case. I would have thought when the OP was learning the subject of strings, that they would have been thought how to join strings in various ways or maybe they, like most others, skipped those chapters.

Anyway, Sajo; you can use JohnH's method on p/#3 or join your strings using a space :
var myString = String.Join(' ',"Dve godine kasnije",ime,"ima",starost,"godina"); - String.Join Method (System)
or concatenation :
string x = String.Concat("Dve godine kasnije",ime,"ima ",starost," godina"); - String.Concat Method (System)
Though I'd prefer p/#3.

What makes line 13 work but not line 20?
 
Back
Top Bottom