Random Insanity Alliance Forum, Mark V

Cactuar Zone => Random lnsanity => Topic started by: SWAT128 on February 22, 2012, 01:02:46 am

Title: lol, C++
Post by: SWAT128 on February 22, 2012, 01:02:46 am
Quote
#include <iostream>
using namespace std;

void divisibleBy (int x){

void divisibleBy (int x){

if (x % 5){
    cout << "is divisible by five " << endl;
}else{
    cout << "is not divisible by five " << endl;
}
 if (x % 10){
    cout << "and divisible by ten" << endl;
}else{
    cout << "but not divisible by ten" << endl;
}


}



int main()
{
  int b;

    char Answer;

    cout << "Please enter a number" << endl;

  cin >> Answer;



  divisibleBy(Answer);

  return 0;
}


I'm making a function to see if a number the user inputs is divisible by five and ten. The problem I'm having is that no matter what number I put in, it says it's divisible by both five and ten.



Edit: Made that change and now it's telling me numbers that are divisible by five aren't.
Title: Re: lol, C++
Post by: Pterrydactyl on February 22, 2012, 01:09:46 am
Code: [Select]

#include <iostream>
#include <cmath>
using namespace std;

void DivisibleBy(int);

void main()
{
  int A=0;
    cout << "Please enter a number" << endl;
  cin >> A;
  DivisibleBy(A);
System("Pause");
}

void DivisibleBy(int A)
{

if (A%5==0)
{
cout << endl<<  A << " is divisible by 5"<<endl;
if (A%10==0)
cout << endl<<  A << " is also divisible by 10"<<endl;
}
}




Gimmie a min and I'll show corrections on yours
Title: Re: lol, C++
Post by: Pterrydactyl on February 22, 2012, 01:15:14 am
#include <iostream>
using namespace std;

void divisibleBy (int x){     You should only have prototypes above the main

if (x % 5){ Using modulus is good, but you need to compare it to something,  x%5==0  should be the condition.  Basically, you will use modulus to get the remainder, and compare it to 0, if it's 0, then it's divisible by 5.
    cout << "is divisible by five " << endl;
}else if (x%!5){   A bit repetitive, you don't need an else if here, you can use just an else.
    cout << "is not divisible by five " << endl;
}
 if (x % 10){  This should be within the If of the check to see if it is divisible by 5
    cout << "and divisible by ten" << endl;
}else if (x%!10){
    cout << "but not divisible by ten" << endl;  This is unnecessary, but you could put it into the else where it says not divisbile by 5 because if it's not divisible by 5, it's definatly not divisible by 10
}


}



int main()
{
  int b;

    char Answer;

    cout << "Please enter a number" << endl;

  cin >> Answer;  you need them to input a number, so this sould be cin >> b;  Thts because your using b as your variable.  Answer is a char, which would mean that it would take th enumber, and convert it to an ascii value.



  divisibleBy(Answer);

  return 0;
}
Title: Re: lol, C++
Post by: SWAT128 on February 22, 2012, 01:22:41 am
Quote
Write a C++ function called divisibleBy that takes an integer as a parameter, and prints out the integer and then "is divisible by five" if the integer is evenly divisible by 5, otherwise it prints "is not divisible by five".  If the number IS evenly divisible by 5, also print " and divisible by ten" if it is also divisible by 10, otherwise print " but not divisible by ten".

I have to make it say that it's not divisible by five or ten if it isn't. That's where I'm having trouble, it keeps telling me that everything is divisible by five and ten.
Title: Re: lol, C++
Post by: SWAT128 on February 22, 2012, 01:27:46 am
Code: [Select]
#include <iostream>
using namespace std;



void divisibleBy (int x){

if (x % 5==0){
    cout << "is divisible by five " << endl;
}else{
    cout << "is not divisible by five " << endl;
}
 if (x % 10==0){
    cout << "and divisible by ten" << endl;
}else{
    cout << "but not divisible by ten" << endl;
}


}



int main()
{
  int b;

    char Answer;

    cout << "Please enter a number" << endl;

  cin >> Answer;



  divisibleBy(Answer);

  return 0;
}

It's still giving me fucked up answers.
Title: Re: lol, C++
Post by: Locke on February 22, 2012, 01:59:48 am
This is how I would do it, personally:
Code: [Select]
#include <iostream>
using namespace std;

int main()
{
  int input(0);
  bool five(0), ten(0);

  cout << "Please enter a number: ";
  cin >> input;
  cout << endl;

  if (input%5==0) {five = true;}
  if (input%10==0) {ten = true;}

  if (five==false && ten==false) {cout << "This number is not divisible by either five or ten.\n";}
  if (five==true && ten==false) {cout << "This number is divisible by five, but not by ten.\n";}
  if (five==false && ten==true) {cout << "This number is not divisible by five, but is by ten.\n";}
  if (five==true && ten==true) {cout << "This number is divisible by both five and ten.\n";}

  return 0;
}

Though I don't see anything wrong with Apophis' code.
Title: Re: lol, C++
Post by: Pterrydactyl on February 22, 2012, 02:38:31 am
Swat, read the corrections i did to your code.  Your asking for a number, taking that number in as a character.  which means that when you try to use it as a number, you get a different value.
Title: Re: lol, C++
Post by: Untelligent on February 24, 2012, 07:43:39 am
In other words, change

char Answer;

to

int Answer;
Title: Re: lol, C++
Post by: Gangs on February 24, 2012, 11:23:58 am
Crap...and here i was, about to regal you all with my Indian coding prowess, effectively reinforcing one of the most widely recognised stereotypes against indian society, when Pterrydactyl and locke came along to steeeeel all mah gloreh...
sorry swat, i promise ill be first to reply, the next time you're blind and stupid.
Title: Re: lol, C++
Post by: Crazyman93 on February 24, 2012, 12:51:59 pm
Everything is divisible by five and ten.
It just won't always be a whole number.
Title: Re: lol, C++
Post by: Jenne on February 24, 2012, 09:51:24 pm
Damn it.  Thanks for making my brain hurt.  I learned C in school, not C++, so the syntax still fucks with me.  My roommate took a C++ class a couple years later.  I helped him out with one of his assignments.  Problem was, he didn't tell me it was C++ and not C, so he was less than happy when the teacher asked him who did his assignment for him.

But yeah, char != int. 
Title: Re: lol, C++
Post by: Gangs on February 25, 2012, 02:48:42 am
Im learning python, learnt a bit of c in coll, this shite is easy.
Title: Re: lol, C++
Post by: Jenne on February 25, 2012, 08:01:07 am
Im learning python, learnt a bit of c in coll, this shite is easy.
A lot of the software I use now uses python scripting.  That would be very useful to know, but I've never gotten into it. 
Title: Re: lol, C++
Post by: Gangs on February 25, 2012, 02:25:26 pm
Python is by far, the simplest language i've read.
Go learn some.
Title: Re: lol, C++
Post by: Untelligent on February 26, 2012, 11:15:28 pm
Python is simple as balls.
Title: Re: lol, C++
Post by: Pterrydactyl on February 27, 2012, 03:51:17 pm
Focus on c++.  Bitches love C++.
Title: Re: lol, C++
Post by: Croix on February 27, 2012, 04:03:42 pm
you guys.

sorcery.

stop it.
Title: Re: lol, C++
Post by: Pterrydactyl on February 27, 2012, 04:53:57 pm
The correct term is wizardry.  Sorcerers just polish their ass to level, while wizards actually research and learn shit.
Title: Re: lol, C++
Post by: Jenne on February 27, 2012, 07:40:42 pm
There is so much old code out there that no one is willing/able to upgrade, that learning Fortran is still a marketable skill.  If nothing else, get paid to convert it to C++.  Though Fortran reads just like C, so it's pretty understandable without too much actual knowledge.  You could probably convert it anyway.
Title: Re: lol, C++
Post by: Croix on February 28, 2012, 12:31:29 am
The correct term is wizardry.  Sorcerers just polish their ass to level, while wizards actually research and learn shit.
BY THAT DEFINITION, I DO MEAN SORCERER FOR YOU
Title: Re: lol, C++
Post by: KemMo on February 28, 2012, 01:23:17 am
C++ is great for some things. Python for others. Love em both, throw in Java and you got my main three.  :wub:
Title: Re: lol, C++
Post by: Croix on February 28, 2012, 01:54:59 am
java...
Title: Re: lol, C++
Post by: Pterrydactyl on February 28, 2012, 06:04:25 pm
Java....................
Title: Re: lol, C++
Post by: Locke on February 29, 2012, 03:46:19 pm
The correct term is wizardry.  Sorcerers just polish their ass to level, while wizards actually research and learn shit.
I prefer "sourcerery."

That hurt.

java...
Java....................

Java............................................
Title: Re: lol, C++
Post by: KemMo on March 01, 2012, 11:54:13 pm
RAWKS BUT IS DYING11!!!!11!!!!!!
Title: Re: lol, C++
Post by: Ogaden on March 02, 2012, 02:02:29 am
I cast level 6 array sort