BAD RESULT

Nov 15, 2015 at 6:34pm
Here's the task:
Bank will give family a loan, if every person in the family gets more than (s) money, and also there will be some money left for paying the loan(k). FAmily consists of (n) people. Dad's salary is(t)dollars and moms salary is (m)dollars.Write a program which will tell if the bank will give you the loan or not.Check: if s=1000, k=600,t=3000,m=2000,n=4, the program should say"itll give the loan";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include <iostream>
using namespace std;
int main(){
float k,t,m,s;
int n,a;

cin>>s;
cin>>k;
cin>>t;
cin>>m;
cin>>n;
a=m+t;
if(a/n>s&&a%n==k)
    cout<<"itll give the loan";
else
    cout<<"it wont give";

return 0;
}

When I check I get not the right result
Last edited on Nov 15, 2015 at 6:54pm
Nov 15, 2015 at 6:44pm
Check: if s=1000, k=600,t=3000,m=2000,n=4, the program should say"itll give the loan";


I dont see you doing this anywhere in your code?
Nov 15, 2015 at 6:48pm
That sentence is just for me personaly to check if the program works. The actual person can make his own inputs, its just one of the examples, which should give me that result, though there could be a lot more correct combinations. You can actualy ignore that line
Nov 15, 2015 at 6:50pm
if(a/n>s&&a%n==k)

I don't see you giving "a" a value anywhere in your code.
Nov 15, 2015 at 7:03pm
But even with this line t+m=a it gives me a bad result.
Nov 15, 2015 at 7:05pm
Could you give an example of what numbers to put in in each variable so it should give a loan? I think the problem might be because a is an integer and youre giving it the value of two floats added together.
Nov 15, 2015 at 7:11pm
If I put in s=1000, k=600,t=3000,m=2000,n=4, it should give the loan. I know that i should add 'a' to the float numbers, but if i do that, it gives me error:"invalid operands of types float and int to binary 'operator%'"
Nov 15, 2015 at 7:27pm
closed account (E0p9LyTq)
a % n evaluates to 0 with your example inputs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>

int main()
{
   int k = 600;
   int t = 3000;
   int m = 2000;
   int s = 1000;
   int n = 4;
   int a;

//   cin >> s;
//   cin >> k;
//   cin >> t;
//   cin >> m;
//   cin >> n;

   a = m + t;

    // let's check the test conditions
    std::cout << a / n << "  " << a % n << "\n\n";
   
   if (a / n > s && a % n == k)
   {
      std::cout << "It'll give the loan\n";
   }
   else
   {
      std::cout << "It won't give\n";
   }

   return 0;
}


1250  0

It won't give
Nov 15, 2015 at 7:29pm
Like @FurryGuy said. The problem is that you don't quite know how modulus operator works. You should read up on it on this website or perhaps a search about it on youtube.
Topic archived. No new replies allowed.