Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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