Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

WTF

Name: Anonymous 2008-10-07 12:46

Hey /prog/ can anyone tell me what the hell is going on in this program?

#include <iostream>
using namespace std;

void fun (int data);
void mystery(int data);
void main( )
{
    int data;
    bool start =true;
   
    cout<<"Please enter an integer value : ";
    cin>>data;
    fun(data);
    mystery(data);
   
   
}

void fun(int count)
{
    char index = count;
    while(index >= 0)
    {
        cout<<index;
        index--;
    }
}

void mystery(int count)
{
    char index = count;
    while(index<count)
    {
        cout<<count;
        index++;
    }
}

Name: Anonymous 2008-10-07 12:53

It asks for a number.
It then prints text characters using the inputted number as the ascii code for the charachter and then loops down to 0.

Mystery is missing so it won't compile.
Fun's body should be a for loop.
Start is never used.

So I wouldn't pay too much attention to this simple but awful piece of code.

Name: Anonymous 2008-10-07 12:56

void mystery(int count)
{
    char index = count;
    while(index<count)
    {
        cout<<"this is the count value "<<count<<"\n";
        index++;
    }
}

here is the mystery part of it

Name: Anonymous 2008-10-07 13:09

thanks for the help >>2

Name: Anonymous 2008-10-07 13:11

Mystery does nothing.

index = count

while(index<count)

index will never be less than count

Name: Anonymous 2008-10-07 13:31

it formats your hard drive

Name: Anonymous 2008-10-07 13:34

>>5
You're missing an implicit conversion -- index is of type int, whereas count is of type char. Thus, count is actually set to index % CHAR_MAX, and it is quite possible that index > count.

Name: Anonymous 2008-10-07 14:13

main does not return an int.

Name: Anonymous 2008-10-07 14:17

COOT

Name: Anonymous 2008-10-07 14:33

>>7
s/CHAR_MAX/(CHAR_MAX + 1)/

Name: Anonymous 2008-10-07 14:40


#include <stdio.h>

void fun (int data);
void mystery(int data);
void main(){
    int data;
    bool start=true;
  
    printf("Please enter an integer value : ");
    scanf("%d",&data);
    fun(data);
    mystery(data);
  
}

void fun(int count){
    char index = count;
    while(index >= 0){
        printf("%c",index);
        index--;
    }
}

void mystery(int count){
    char index = count;
    while(index<count){
        printf("%d",count);
        index++;
    }
}

Name: Anonymous 2008-10-07 15:48

>>11
Wow, you did the same thing with printf instead of cout. Are you proud of yourself?

Name: Anonymous 2008-10-07 23:21

Where the fuck is the for loop. Are you not on chapter 3 yet?

Name: Anonymous 2008-10-07 23:24

>>12
He should be.  C > Sepples.

Name: Anonymous 2008-10-07 23:27

prog2.cpp:6: error: ‘::main’ must return ‘int’

Name: Anonymous 2008-10-08 19:56

ITT MORONS WHO DON'T REALIZE THERE'S A FORCED CONVERSION FROM INT TO CHAR

SO MYSTERY DOES WORK

HOLY SHIT WHERE ARE THE EXPERT PROGRAMMERS

Name: Anonymous 2008-10-09 3:08

>>16
ITT people whine about not knowing the obscure intracacies about data type limits. This is 2008, not 1978.  Nobody uses 8 bit values as integers, nor does anyone care about overflow. Goddamn.

Name: Anonymous 2008-10-09 3:57

>>16
MORON WHO DOESN'T REALIZE THAT CHAR AND INT CAN BE THE SAME SIZE, AND CHAR CAN EVEN BE LARGER THAN INT.

Name: Anonymous 2008-10-09 8:01

>>18
Since sizeof(char) == 1, what would that make sizeof(int)?

Name: Anonymous 2008-10-09 8:41

>>19
char is 32 bits.
int is 16 bits of data with 16 bits of padding.
CHAR_BIT == 32
sizeof(char) == 1
sizeof(int) == 1
CHAR_MAX == 2147483647
CHAR_MIN == -2147483648
INT_MAX == 32767
INT_MIN == -32768


this is allowed by the c and c++ standards.

Name: Anonymous 2008-10-09 13:04

this is allowed by the c and c++ standards.
But not by reality.  You probably think LISP is a useful language.

Name: Anonymous 2008-10-09 14:15

>>20
No it's not.
It's guaranteed that SCHAR_MAX <= INT_MAX.
Learn C you fucking faggot.

Whenever I come here, I always rage, because there's always some faggot thinking he knows C.

By the way, just in case you decide to reply back with "you're wrong": chapter and verse.

Name: Anonymous 2008-10-09 14:18

>>22
and by the way, bump this shit because I want you, >>20, to be ridiculed.

Name: Anonymous 2008-10-09 14:20

Anonymous got his ass owned by Anonymous
Fuck yes

Name: Anonymous 2008-10-09 16:33

bump, >>20 is a faggot.

Name: Anonymous 2008-10-09 16:34

Wouldn't it be interesting if >>20,22,23 were all the same people? And we have been trolled constantly.

Name: Anonymous 2008-10-09 17:39

>>22
C99 6.2.5.8

Name: Anonymous 2008-10-10 11:56

>>27
I don't have to look at that section, I know you're wrong.
But whatever, let's see.
Well, no 6.2.5.8 section.
Perhaps you meant 6.2.5 verse 8.
Very well,

For any two integer types with the same signedness and different integer conversion rank
(see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a
subrange of the values of the other type.

Now, I'm curious, how do you interpret this?
It says I'm correct, and that you're wrong.

FUCKING BUMP YOU FUCKING STUPID SHIT.
I CAN'T BELIEVE YOU ACTUALLY BOTHERED SEARCHING THE STANDARD IN BELIEF THAT YOU WERE RIGHT.

>>26
And we have been trolled constantly.
Listen you fucking 3-months-here faggot (been trolled at constant/exponential etc rate, all that xkcd/reddit/digg fail), I'm not >>20
I don't give a shit whether you believe me or not.
now, FUCK YOU. FUCK YOU. FUCK YOUA FUCK YOU FUCKYOU.

bump. fucking bump.

Name: Anonymous 2008-10-10 13:50

Someone is wrong on the internet.

Name: Anonymous 2008-10-10 13:51

bump.

Name: Anonymous 2008-10-10 13:53

>>29
Yes you fucking piece of shit, someone is wrong on the internet, about programming, and this is a programming board.
Just because you can't understand jack shit about what I'm talking about in >>28, doesn't mean I shouldn't be posting it.
So fuck you, bump. >>20 is a faggot, and I'm still waiting for a reply from him.

Name: Anonymous 2008-10-10 13:57

>>31
Nobody cares.  Kill yourself.

Name: Anonymous 2008-10-10 14:10

>>32
no. bump, it's about time you faggots get taught some C

Name: Anonymous 2008-10-10 14:50

>>31
someone is wrong on the internet

LOL YOU REFERENCED XKCD, AAAAAAAAAAAAAAAAyou're a stupid fuck, please fuck off and dieHAHAHAHAH

Name: Anonymous 2008-10-10 15:58

>>28
YHBT

Name: Anonymous 2008-10-10 17:54

>>35
I don't care.
bump.

Name: Anonymous 2008-10-10 18:32

>>22
the standard does not guarantee that.

Name: Anonymous 2008-10-10 18:47

>>35
the standard does not guarantee that.

Name: Anonymous 2008-10-10 19:49

>>21
I lol'ed

Name: Anonymous 2008-10-11 0:47

>>38
ed does not guarantee that

Name: Anonymous 2008-10-11 1:06

When I use a compiler, I don't want eighty extra MEGABYTES of worthless
modules and garbage collecting code!  I just want a Compiler!!
Not a "javaompiler".  Not a "pythonompiler".  Those aren't even WORDS!!!! C!
C! C IS THE STANDARD!!!

Name: Anonymous 2010-12-21 15:26

Don't change these.
Name: Email:
Entire Thread Thread List