im a Beginner

Write your question here.
I'm trying to write s small program to get an input value of variable x and then calculate the expression "((x/3) + (x%)) * 3 = y" where y equals the expression. I'm having trouble because of the module I don't know what im doing wrong. can anybody help me?

#include <iostream>
using namespace std;

int main ()
{
double x, y, %;
cout << "Enter x here" <<;
y=((3/3) + (3%3)) * 3;

cout << y << "is" <<;
return 0;
}
Hello!

There were several small mistakes going on in your code. First of all, you declare x and y as double, modulo only works with integers. Also you wish to have input, so you must use cin << x; All that is then needed is the output part. Here is a complete example that should do what you wish to achieve. Hope it helps. :)

1
2
3
4
5
6
7
8
9
10
   int main()
{
   int x = 0, y = 0;
   cout << "Enter x here: ";
   cin >> x; 

   cout << "\nY is: " <<  (y = (x / 3) + (x % 3) * 3);

   return 0;
}


Just for sake of explanation: "\n ..." before Y is standing for newline. The same can be achieved by putting << endl at the end of line 5. ;-)
Last edited on
% is an operator, and can't be used as a variable name. It stands for modulus, which is "remainder" sort of if you remember elementary school division.

if you want a percent, you need to divide by 100 or calculate something like (value/maxvalue). For example, if you have 80%, that is really just decimal 0.80. If you get 8 out of 10 things, that is 8/10 % of the total, or again, 0.80

if you divide integers, you get an integer. so 5/6 = 0 !!!
you have to force it to use floating point via 1/3.0 = 0.33333 etc (so the above program might give issues, it should be x/3.0) if you want decimals)

so I think you want
double x,y;

y= x/3.0 +(x/100.0 *3);

if I understood what you typed.


If that isn't what you wanted, can you possibly put the equation you want to solve into strict reverse polish form or strict algebraic form in a very clear way?



Last edited on
HI. i got the same problem. Thanks :)
Last edited on
Topic archived. No new replies allowed.