Adding!

This is a discussion on Adding! within the C# Programming forums, part of the General Programming Boards category; Hello, I'm learning C++ and Dot Net and I hope this is the right forum. I'm very new to this ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    2

    Adding!

    Hello,

    I'm learning C++ and Dot Net and I hope this is the right forum. I'm very new to this game and I see to be having a little problem and was wondering if someone could shed some time.

    The code below basicalyl asks a few questions (more will be added) and multiples the answer by the rate. What I want to do at the end is to add up all the results. So for example, TMB and TGB would be 5 each, so the total would be 10. But when I do it, it doesn't give me the right #. If TMB is 1.25 and TGB is 1.25, the answer should be 2.50, instead it reads out as 2. The error tells me that
    warning C4244: '=' : conversion from 'double' to 'int', possible loss of data

    I'm so lost on this part and if anyone could shed some light, i would be deeply appreciative.

    Thanks

    Code:
    void selectMenu(int option)
    {
    	int mb=0;
    	double tmb=0.0;
    	int gb=0;
    	double tgb=0.0;
    	int sum=0;
    	
    		switch (option)
    	{
    	default:
    	     Console::WriteLine("Error");
    	case 1:
    		Console::WriteLine("Megabytes?");
    		mb=Convert::ToInt32(Console::ReadLine());
            tmb=mb*0.25;
    		Console::WriteLine("{0}", Convert::ToString(tmb));
    		Console::WriteLine("Gigabytes?");
    		gb=Convert::ToInt32(Console::ReadLine());
            tgb=gb*0.25;
    		Console::WriteLine("{0}", Convert::ToString(tgb));
    		sum=tmb+tmb;
    		Console::WriteLine("{0}", Convert::ToString(sum));
    		
    		break;
    	case 2:
    		Console::WriteLine("This is option 2");
    		break;
    	case 3:
    		Console::WriteLine("This is option 3");
    		break;
    	}
    
    }

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    53
    The sum should be a double and not a int

    JMD

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    2
    Quote Originally Posted by nbo10
    The sum should be a double and not a int

    JMD

    I am a idiot! Sorry for bothering you and I appreciate it!

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with storing the last value of a loop and adding it?
    By colmustang in forum C Programming
    Replies: 4
    Last Post: 03-08-2008, 08:31 AM
  2. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 02:44 PM
  3. Java: Sorting and Adding a Row in Table
    By alphaoide in forum Tech Board
    Replies: 4
    Last Post: 08-12-2005, 08:22 PM
  4. Adding your own API calls.
    By 0x7f in forum Windows Programming
    Replies: 1
    Last Post: 04-08-2003, 06:00 PM
  5. Adding and subtracting time?
    By JCCC in forum C Programming
    Replies: 3
    Last Post: 03-29-2002, 01:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21