% operator

Pages: 123
@cokane: your code is correct (how else could it; you've quite literally copied Perman's code), but it seems like you don't know how to use functions. Your compiler should throw useful errors right now.
Gaminic, I such at noob at C++. I am trying to learn it via an online class. I really wish the class was a real class so I could actually get one on one help from my professor or classmates. But interaction in my class isnt very good because most of the students don't log on very much. However the interaction on the forum is much much better.
cokane:

The code is not correct. Fix the stuff I underline and you are good. Remember in your concole out statement remainder is a function call and not a variable. So when you run the function cout() it call the function remainder() which return the remainder as an int which on the other hand is the one cout() print out on the concole.
Here is the code with the fix underlined.

1
2
3
4
5
6
7
8
9
int main (int a, int b){
    cout << "Enter a divisor! and press Enter \n";
    cin >> a;
    cout << "Enter a dividend! and press Enter \n";
    cin >> b;
    cout << "The remainder of those numbers is " << remainder(a, b) << endl;
    system("PAUSE");
    return 0;
}


Congratulation. It works great. Now you have something you can build on.
Good luck Buddy.

Gaminic:

The compiler does not generate an error. Not mine at least. It think the remainder is a variable that exist. I could run the program and it put out crap as the remainder but it ran. Try it on yours if you use something else than Borland.
Last edited on
cokane.

Now you are done finding out how to get the remainder without using modulo (%) I have an exercise for you.

Using the program you made copy it to a new program called Round.cpp.
Using the (%) make a program that round a number to the nears 10.

Rename the function remainder() to rounder() and do the rounding in that function and return the rounded number.
Number can be between 0 - 1000 and print out the rounded number.
Example:

Enter: 1234
Result: 1230

This exercise will teach you how to get use to function calls which is a main factor in C++.

Good luck and ask questions. I will help.
Per
The compiler does not generate an error. Not mine at least. It think the remainder is a variable that exist. I could run the program and it put out crap as the remainder but it ran. Try it on yours if you use something else than Borland.


I'm guessing it was a pointer, as 'remainder' is a function pointer as far as Main is concerned.
Topic archived. No new replies allowed.
Pages: 123