Rob83
02-17-2005, 04:14 PM
I'm trying to do something in Dot Net and am having an issue.
Here is the code:
void selectMenu(int option)
{
int mb=0;
double tmb=0.0;
int gb=0;
double tgb=0.0;
int sumTotal =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));
sumTotal=Convert::ToString(tmb+tgb);
Console::WriteLine("{0}", Convert::ToString(sumTotal));
break;
case 2:
Console::WriteLine("This is option 2");
break;
case 3:
Console::WriteLine("This is option 3");
break;
}
}
The area is bold is wrong. I know, i was just testing. But here is my problem. Whether I convert it to Int32 or not, if MB = 1.25 and GB = 1.25, when it adds, it gives me 2.5 instead of 2.
This is actually for school nto for real life. I know I can this error:
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
so how do I convert it back? Any help is really appreciated!
Here is the code:
void selectMenu(int option)
{
int mb=0;
double tmb=0.0;
int gb=0;
double tgb=0.0;
int sumTotal =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));
sumTotal=Convert::ToString(tmb+tgb);
Console::WriteLine("{0}", Convert::ToString(sumTotal));
break;
case 2:
Console::WriteLine("This is option 2");
break;
case 3:
Console::WriteLine("This is option 3");
break;
}
}
The area is bold is wrong. I know, i was just testing. But here is my problem. Whether I convert it to Int32 or not, if MB = 1.25 and GB = 1.25, when it adds, it gives me 2.5 instead of 2.
This is actually for school nto for real life. I know I can this error:
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
so how do I convert it back? Any help is really appreciated!
