Advertisement

Console.writeline Not Printing Out Expression. C#

Started by July 31, 2016 10:05 PM
7 comments, last by ccuccherini 8 years, 4 months ago

Why does this code not work?


Console.WriteLine(7/2)

It doesn't print anything on the console.

Works for me. What does your code look like?
Advertisement

Are you getting any sort of errors when you try and make it print the line or is the window just staying blank?

No errors at all :|

Here's the full code..


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Variables_and_Operators
{
    class Program
    {
        static void Main(string[] args)
        {
            //do not write decimals in byte or int. 20.0 is different from 20 in C#. Lol.
            byte userage = 20;
            int NumberOfEmployees = 210;
            //you can hold integral numbers with double, float and decimal despite them be using for decimals. 
            double hip = 15;
            float slip = 30;
            decimal grip = 45;
            //you need to add f in the float variable after the number to turn it into a float and for the compiler to recognize it exactly as a float. You need to add m to turn decimal into decimal.
            double strom = 15.322;
            float group = 15.753f;
            decimal shopper = 99.12345m;
            //this is a char data type, when initializing char, use ' instead  of ".
            char grade = 'A';
            //this is a bool
            bool promote = true;
            //you can store multiple variable in the same line as long as they are the same type.
            byte bob = 50, stanley = 90;
            //you can initialize a variable on a different statement.
            byte year;
            year = 157;
            int x = 1, y = 2;
            x = y + x; // x <- y... Aka when x = y, the value of y goes to x. y stays the same, x changes to y.
            y = x; // y <- x... y still stays the same since x is 2 and y was already 2.
            Console.WriteLine(x);
            Console.WriteLine(y);
            Console.Read();
            //as long as there is one non integer number in the equation, you will get a non integer value other wise it will be truncated.
            Console.WriteLine(7 / 2);
            Console.WriteLine(7.0 / 2);
            Console.WriteLine(7 / 2.0);
            Console.WriteLine(7.0 / 2.0);
            x++; //increases a value by 1
            x--; //decreases a value by 1
            //++ can be placed before a variable or after it, it affects the sequence in which tasks are performed.
            int counter = 1;
            Console.WriteLine(counter++); //prints the original value of counter and then it increments the value. As in it will print the original value but not the value++.
            Console.WriteLine(++counter); //increments the value then prints the new value.
            //converts 20.9 into an integer.
            x = (int)20.9;
            //Another way to declare a float or decimal without f or m. Remember that all numbers with decimals are treated as double first.
            float num1 = (float)20.999999999;
            decimal num2 = (decimal)20.53;


        }
    }
}

It's messy but ehhhhhhhhhhhhhhhhhh.

No errors at all :|

Here's the full code..


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Variables_and_Operators
{
    class Program
    {
        static void Main(string[] args)
        {
            //do not write decimals in byte or int. 20.0 is different from 20 in C#. Lol.
            byte userage = 20;
            int NumberOfEmployees = 210;
            //you can hold integral numbers with double, float and decimal despite them be using for decimals. 
            double hip = 15;
            float slip = 30;
            decimal grip = 45;
            //you need to add f in the float variable after the number to turn it into a float and for the compiler to recognize it exactly as a float. You need to add m to turn decimal into decimal.
            double strom = 15.322;
            float group = 15.753f;
            decimal shopper = 99.12345m;
            //this is a char data type, when initializing char, use ' instead  of ".
            char grade = 'A';
            //this is a bool
            bool promote = true;
            //you can store multiple variable in the same line as long as they are the same type.
            byte bob = 50, stanley = 90;
            //you can initialize a variable on a different statement.
            byte year;
            year = 157;
            int x = 1, y = 2;
            x = y + x; // x <- y... Aka when x = y, the value of y goes to x. y stays the same, x changes to y.
            y = x; // y <- x... y still stays the same since x is 2 and y was already 2.
            Console.WriteLine(x);
            Console.WriteLine(y);
            Console.Read();
            //as long as there is one non integer number in the equation, you will get a non integer value other wise it will be truncated.
            Console.WriteLine(7 / 2);
            Console.WriteLine(7.0 / 2);
            Console.WriteLine(7 / 2.0);
            Console.WriteLine(7.0 / 2.0);
            x++; //increases a value by 1
            x--; //decreases a value by 1
            //++ can be placed before a variable or after it, it affects the sequence in which tasks are performed.
            int counter = 1;
            Console.WriteLine(counter++); //prints the original value of counter and then it increments the value. As in it will print the original value but not the value++.
            Console.WriteLine(++counter); //increments the value then prints the new value.
            //converts 20.9 into an integer.
            x = (int)20.9;
            //Another way to declare a float or decimal without f or m. Remember that all numbers are treated as double first.
            float num1 = (float)20.999999999;
            decimal num2 = (decimal)20.53;


        }
    }
}

It's messy but ehhhhhhhhhhhhhhhhhh.

That's okay.

Comparing what you put in for all your writelines and what fastcall put in in there's it seems to be that you are missing System. before all of them. If you aren't getting any print outs try reformatting them to System.Console.WriteLine and see if that works.

NVM FOUND THE ERROR.

Advertisement

NVM FOUND THE ERROR.

Awesome! What ended up being the issue?

Console.Read() was at the wrong location.

Ohh okay. Good detective work!

This topic is closed to new replies.

Advertisement