Jace
❔ i need help finding how many 10s, 5s, 2s and 1s are in the number 18.
Im really having trouble finding the solution... i tried the division and modulo.. heres the code ive done :
//Goal: Write a program that asks the user for a cash amount and calculates the number of $10, $5, $2 and $1 bills that must be collected to obtain this amount.
//varialbes
int totalAmount;
int tenDollars;
int fiveDollars;
int twoDollars;
int oneDollars;
//variable for when i have the final result of 10s,5s,2s and 1s.
int resultTenDollars;
int resultFiveDollars;
int resultTwoDollars;
int resultOneDollars;
//contants
const int amountTenDollars = 10;
const int amountFiveDollars = 5;
const int amountTwoDollars = 2;
const int amountOneDollars = 1;
//person enters a value for the varible in the console
Console.WriteLine("Enter the total amount:");
totalAmount = int.Parse(Console.ReadLine());
//calcul ( this is where im not very sure what to do )
tenDollars = totalAmount/ amountTenDollars;
resultTenDollars = tenDollars; //1,8
fiveDollars = totalAmount % 5; //1,8
resultFiveDollars = fiveDollars;
twoDollars = totalAmount % 2; //1,8
resultTwoDollars = twoDollars;
oneDollars = totalAmount % 1; //0,8
//showing the result to the console
Console.WriteLine(tenDollars); //1
Console.WriteLine(fiveDollars); //3
Console.WriteLine(twoDollars); //0
Console.WriteLine(oneDollars); // 0
answer should be : 1 for 10s, 1 for 5s, 1 for2s and 1 for 5s ;/
142 replies
✅ Cant resolve this problem
What im trying to do is : Exchange the value of each variable.
Example, if x = 3 and y = 10 and we run the program, x will be 10 and y will be 3.
The problem is that when im running the code, x is the same number as y....
i cant figure out how to make this code work..
double x;
double y;
Console.WriteLine("enter x");
x = double.Parse(Console.ReadLine());
Console.WriteLine("enter y");
y = double.Parse(Console.ReadLine());
x = y;
y = x;
Console.Write("new x :");
Console.WriteLine(x);
Console.Write("new y value :");
Console.WriteLine(y);
86 replies