• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Visual C question

1) That isn't Visual C, it's c#, and console based
2) It isn't going to do anything because your main method exits without doing anything. IIRC, visual studio will pop up a command box for a command line application and it will close as soon as the program finishes so you'll just see a quick flash of it.
3) To run it, hit the lovely green arrow directly under the "Window" menu
 
Originally posted by: kamper
1) That isn't Visual C, it's c#, and console based
2) It isn't going to do anything because your main method exits without doing anything. IIRC, visual studio will pop up a command box for a command line application and it will close as soon as the program finishes so you'll just see a quick flash of it.
3) To run it, hit the lovely green arrow directly under the "Window" menu

Ya, that green arrow is the debug button. So how do I fix it to show something? This is my first time working with this so...
 
You need to pause and wait for a key at the end, otherwise the console exits too fast for you to see anything. Try Console.ReadKey or Console.ReadLine. The first method will return as soon as the user pressed a key. The second method will return when the user presses enter to end a line.
 
Originally posted by: Markbnj
You need to pause and wait for a key at the end, otherwise the console exits too fast for you to see anything. Try Console.ReadKey or Console.ReadLine. The first method will return as soon as the user pressed a key. The second method will return when the user presses enter to end a line.

Where would you put that in the code? I tried after declaring the variables and after the return, it gives me this error: Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement C:\Documents and Settings\moe\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 15 13 ConsoleApplication1

Sorry to ask, but would you put it where its supposed to be, I just started this so...🙁
 
Put it before the return statement

Once the return statement executes; all code afterwards within the function will not execute within that call to the function.
 
You'd better post that code. There's something more wrong with it then just the location of the statement.
 
The first code worked after using Console.Realine(), but now I'm trying a different code and the method doesn't work:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
int fun0()
{
int i;
for(i = 0; i < 100; i++)
if( i == 100 )
i = 0;
else
i *= 2;
Console.ReadLine();
return(i);
}
}
}

it compiles with no errors, but doesn't display anything.
 
First it does not look like your function is ever called.

Second where in your function(s) do you output anything?

Your function returns an integer. What is done by which ever code area that calls the functions.

I looks like you have a basic building block - the overall skeleton needs to be fleshed out.
 
Originally posted by: EagleKeeper
First it does not look like your function is ever called.

Second where in your function(s) do you output anything?

Your function returns an integer. What is done by which ever code area that calls the functions.

I looks like you have a basic building block - the overall skeleton needs to be fleshed out.

I'm still a beginner so I really don't know how to call functions and all that, basically some tracing problems were posted and I was going through them, but to know if I'm right or wrong I need to run it. I'd love to learn this on my own, it sucks to ask but would you just fix this code so I could just keep putting in the different questions after trying them to check the answer if possible.
 
You should learn how to call functions at the same time as learning to write them. Stop using fun0() and put everything in the Main method for now.
 
Originally posted by: kamper
You should learn how to call functions at the same time as learning to write them. Stop using fun0() and put everything in the Main method for now.

Main method...I don't know what to do with that. Change fun0() to main() like in normal C or remove namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}

neither works. Sorry.
 
Fixing the code for you will npot help you learn from your mistakes.

The best that we should do to help you is to point out where you are making mistakes and let you figure out how to correct them.

You may wish to learn how to build a Hello World program and then expand from there in small steps.
 
Originally posted by: mOeeOm
The first code worked after using Console.Realine(), but now I'm trying a different code and the method doesn't work:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
int fun0()
{
int i;
for(i = 0; i < 100; i++)
if( i == 100 )
i = 0;
else
i *= 2;
Console.ReadLine();
return(i);
}
}
}

it compiles with no errors, but doesn't display anything.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//caller
console.writeline(fun0)

}
int fun0()
{
int i;
for(i = 0; i < 100; i++)
if( i == 100 )
i = 0;
else
i *= 2;
Console.ReadLine();
return(i);
}
}
}
 
Originally posted by: kamper
You should learn how to call functions at the same time as learning to write them. Stop using fun0() and put everything in the Main method for now.

what are u talkin,

int _ = 0;
int __ = 123;
int ___ = _ + __;

int ____(int _) {
return (___++) - _;
}

THERE U GO 🙂
 
Originally posted by: kamper
Originally posted by: beggerking
console.writeline(fun0)
Wtf? Assuming that even compiles, wouldn't it print something along the lines of the address of the method?

no, it will simply call the function, take the result, and pass it to the writeline function. If fun0 takes an int and returns an int, we can do:

console.writeline(fun0(fun0(fun0(fun0(1)))))
 
Originally posted by: SoftwareEng
Originally posted by: kamper
Originally posted by: beggerking
console.writeline(fun0)
Wtf? Assuming that even compiles, wouldn't it print something along the lines of the address of the method?
no, it will simply call the function, take the result, and pass it to the writeline function. If fun0 takes an int and returns an int, we can do:
console.writeline(fun0(fun0(fun0(fun0(1)))))
So you can call methods in c# without using parentheses? 😕 I remember doing that in pascal but never anything else...
 
Back
Top