Задача 6. Благотворителна кампания - какъв е проблемът с кода ми?
Здравейте!
Решавам задача 6. от домашното и се сблъсквам с един проблем. Трябва да извадя 1/8 от общата сума.
double finalprofit = sum - 1/8 * sum; - не работи
double finalprofit = sum - sum / 8; - работи
Защо моят код не работи?
Благодаря предварително!
П.С Съжалявам, ако въпроса е глупав, но от скоро се занимавам с програмиране.
Здравейте имам проблем с една задача, някой знае ли какъв е:
https://pastebin.com/uQuKjNx8
import java.util.Scanner;
public class BackToTheFuture {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double inheritanceMoney = Double.parseDouble(scanner.nextLine());
int yearsToLiving = Integer.parseInt(scanner.nextLine());
int yearsIvan = 18;
for (int currentYear = 1800; currentYear < yearsToLiving; currentYear++) {
if (currentYear % 2 == 0) {
inheritanceMoney -= 12000;
} else {
inheritanceMoney -= (12000 + 50 * yearsIvan);
}
yearsIvan++;
}
if (inheritanceMoney > 0) {
System.out.printf("Yes! He will live a carefree life and will have %.2f dollars left.", inheritanceMoney);
} else {
System.out.printf("He will need %.2f dollars to survive.", Math.abs(inheritanceMoney));
}
}
}