dividing by any numbers = 4354302

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 894 Views - Last Post: 03 February 2018 - 07:27 PM Rate Topic: -----

#1 kianyt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-February 18

dividing by any numbers = 4354302

Posted 03 February 2018 - 04:15 PM

Hi, i am trying to make a basic dividing code, but no matter what numbers i use the output is 4354302, can anyone help

 
#include <iostream>
#include <cstdlib>
#include <iomanip>

using namespace std;

int main()
{


    int totalReviews;
    int positiveReviews;
    int percentagePositive;

cout << "Please Enter your total reviews" << endl;
cin >> totalReviews;

cout << "Please Enter your positive reviews" << endl;
cin >> positiveReviews;

percentagePositive == positiveReviews / totalReviews;

    cout << percentagePositive << endl;


    return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: dividing by any numbers = 4354302

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13752
  • View blog
  • Posts: 54,912
  • Joined: 12-June 08

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:17 PM

Remember == and = are different.

== is used to compare two objects and returns a boolean.
= is for assignment.

You should also think about the results.. integers are whole numbers - so no decimal points. Any remainders may be missing.
Was This Post Helpful? 2
  • +
  • -

#3 kianyt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-February 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:18 PM

OK i changed it and now it just outputs 0, any ideas?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13752
  • View blog
  • Posts: 54,912
  • Joined: 12-June 08

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:22 PM

What numbers are you using?
Did you look into something that may show a remainder? Again, integers are whole numbers.
Was This Post Helpful? 1
  • +
  • -

#5 kianyt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-February 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:24 PM

just for now i used 100 and 80, just to test as it is very easy, but 0, and if i change positiveReviews to float it makes no difference, still 0
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13752
  • View blog
  • Posts: 54,912
  • Joined: 12-June 08

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:29 PM

Let's see the current code.
Was This Post Helpful? 1
  • +
  • -

#7 kianyt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-February 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:30 PM

here you go
#include <iostream>
#include <cstdlib>
#include <iomanip>

using namespace std;

int main()
{


    int totalReviews;
    int positiveReviews;
    float percentagePositive;

cout << "Please Enter your total reviews" << endl;
cin >> totalReviews;

cout << "Please Enter your positive reviews" << endl;
cin >> positiveReviews;

percentagePositive = positiveReviews / totalReviews;

    cout << "Your percentage of positive results is " << percentagePositive << endl;


    return 0;
}


Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13752
  • View blog
  • Posts: 54,912
  • Joined: 12-June 08

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:33 PM

Think about casting your division problem to a float while assigning it to the float.
Was This Post Helpful? 0
  • +
  • -

#9 kianyt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-February 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:41 PM

Ok i fixed it by doing that, here is the current code.
Now I would like to be able to tell the user how many more positive reviews they would need to have a 90% positive review percentage, but it would need to be of the new percentage, not of the old. for example if a user had 80 positive reviews out of 100 total reviews, it would tell him that he needs a minimum of 100 more positive reviews to get a 90% positive review rate. I have no idea how to do that, and would be great if i could get some pointers

#include <iostream>
#include <cstdlib>
#include <iomanip>

using namespace std;

int main()
{


    int totalReviews;
    int positiveReviews;
    float percentagePositive;

cout << "Please Enter your total reviews" << endl;
cin >> totalReviews;

cout << "Please Enter your positive reviews" << endl;
cin >> positiveReviews;

percentagePositive = (float)positiveReviews / (float)totalReviews;

cout << "Your percentage of positive results is " << percentagePositive*100 << endl;


    return 0;
}


Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13752
  • View blog
  • Posts: 54,912
  • Joined: 12-June 08

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:47 PM

It's an algebra equation.

Now:
percent = positive / total

If you want positive, but have a percent and total how would you go about solving for positive?
Was This Post Helpful? 1
  • +
  • -

#11 kianyt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-February 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 04:54 PM

I understand that but say if someone has 80/100, and they get 10 more positive, it wont be 90/100, it will be 90/110, so 81.8%, so I need to write a line of code that will tell a user how many more positive they need for 90%, which in this case would be 100, as 180/200 is 90%
Was This Post Helpful? 0
  • +
  • -

#12 tony jay  Icon User is online

  • New D.I.C Head

Reputation: 17
  • View blog
  • Posts: 42
  • Joined: 31-January 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 05:15 PM

Your problem is not coding currently.
If you can do the maths on the back of an envelope, then coding the resultant equation is trivial.

So sit down with pen and paper and solve the problem there...
Was This Post Helpful? 1
  • +
  • -

#13 kianyt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-February 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 05:20 PM

oh forgot to update, I've got it finished now
Was This Post Helpful? 0
  • +
  • -

#14 tony jay  Icon User is online

  • New D.I.C Head

Reputation: 17
  • View blog
  • Posts: 42
  • Joined: 31-January 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 05:22 PM

Well done!

You seem to be having a busy day today...
Was This Post Helpful? 1
  • +
  • -

#15 kianyt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 03-February 18

Re: dividing by any numbers = 4354302

Posted 03 February 2018 - 05:25 PM

yeah, starting 11th grade CIT (coding / computer study), and want to get as far into it as I can during the long weekend that i have

thanks for help all
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2