Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

C# integers


  • Please log in to reply

#1
BTPH

BTPH

    Member

  • Member
  • PipPipPip
  • 167 posts
okay ive got an assigment where i have to build a program for sorting out the rental details of cars,

one of the things id like to do is ensure that if a user enters a number with a decimal the program will round it up to the nearest whole number
i.e 30.1 =31

the program will also make various calculations based on user input, i need all of these to be whole numbers, im not too familiar with C#, can anyone offer help?
  • 0

Advertisements


#2
TheQuickBrownFox

TheQuickBrownFox

    Member

  • Member
  • PipPipPip
  • 714 posts
Hi there. We really don't directly help out with school work in this site. We could however point you to the right resources.
You should try using MSDN as your reference. http://msdn.microsof...rp/default.aspx

I'm sure you'll find your answer there (though not directly).

Personally, I consider codeproject.com as my favorite reference for source code help and explanations on how to do some things.
  • 0

#3
BTPH

BTPH

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 167 posts
thanks for the links trackster, they helped out, now for my latest problem, i have a string called vehicle1, i also have the strings make1, model1, year1, rego1
i would like vehicle1 to equal
make1, model1, year1 and rego1, this is the line ive typed
GlobalVariables.vehicle1 = Convert.ToString(Console.WriteLine("{0}, {1}, {2}, {3}", GlobalVariables.make1, GlobalVariables.model1, GlobalVariables.year1, GlobalVariables.rego1));
i keep getting an error message
cannot convert from 'void' to 'object' anyone know how i can solve this?
(i put GlobalVariables in front of each variable name because i have defined all the variables in a class called GlobalVariables(), this allowing me to have, you guessed it, global variables)
  • 0

#4
TheQuickBrownFox

TheQuickBrownFox

    Member

  • Member
  • PipPipPip
  • 714 posts

GlobalVariables.vehicle1 = Convert.ToString(Console.WriteLine("{0}, {1}, {2}, {3}", GlobalVariables.make1, GlobalVariables.model1, GlobalVariables.year1, GlobalVariables.rego1));


The return type of Console.WriteLine() is void. Convert.ToString() needs an Object parameter.

In short, you're not really inputting anything in the ToString() method.
  • 0

#5
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP

one of the things id like to do is ensure that if a user enters a number with a decimal the program will round it up to the nearest whole number
i.e 30.1 =31

Read the number in as a float/double, then convert it to integer (implemented as truncation), and then add 1.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP