Aia 1,977 Nearly a Posting Maven

@sk8ndestroy14
I asume you are writing concerning Dave's latest comment?.
Do you realize he is not dening anything, but pointing out some interesting ways how these studies gets propagated?

Aia 1,977 Nearly a Posting Maven

Actually, I don't really care about that. I bring that up to point out that someone who worships science really ought to be able to quote chapter and verse of scientific data.

Oh, don't worry he will answer back to you about that. I am as sure as the sun will rise tomorrow, and that can be proved.

Aia 1,977 Nearly a Posting Maven

Actually humans started smoking because they ARE of superior intelligence.

And then the smoke got to our heads.

Aia 1,977 Nearly a Posting Maven

>because one of the dimension required by the compiler is missing......

Is not missing. The compiler knows already about it.
Read the link that I pointed to you previously and you'll understand.

Aia 1,977 Nearly a Posting Maven

>what is the implication of such a declaration
You are passing a multidimentional array as a parameter. Look here for more information

However it shout be more like:
int sort( data type list[][a])
{
/*statements*/
}

Aia 1,977 Nearly a Posting Maven

Also, C was originally developed on a 16-bit machine with only 32K words of memory. Memory space was a premium commodity.

Yes.

>i found that the limits of int and short int are the same

Also C is supposed to be a portable program language, which means that in theory you could use it for different platforms or architectures.
That's the reason why C defines only the minimum store sizes:
the size of type short is at least two bytes, long at least four bytes and long long at least eight bytes. And even when they can be larger that their minimun size, it must follow this order:
sizeof( short ) ≤ sizeof( int ) ≤ sizeof( long ) ≤ sizeof( long long )
Check it out and you'll see that this applies to your machine.

Aia 1,977 Nearly a Posting Maven

Question from an ignorant:
Why 1679?

Aia 1,977 Nearly a Posting Maven

Considering that you have 1GiB of RAM, you need to get a decent graphic card if you already haven't got one.

Exactly my thought, when I posted earlier.

Aia 1,977 Nearly a Posting Maven

Video card speed and capability is more important for gaming.

Aia 1,977 Nearly a Posting Maven
if (b1[i][j] = '*')

This will always evaluate to TRUE, probably you ment "=="

There's also a problem with a "hanging" else.

Aia 1,977 Nearly a Posting Maven

As a side note:
Instead of using inlinecode surrounding your code, use code.
The back slash '\" needs to be forward "/" inside the tag.

Aia 1,977 Nearly a Posting Maven

No hay de que!

Aia 1,977 Nearly a Posting Maven

Dev-C++ doesn't have a problem compiling it.

void main should be int main( void )


Also I don't understand why you didn't prototyped the function as you declared.

long transformaclave( const char* cl)
long transformaclave( const char c[ ]);

It appears to me that your compiler doesn't like that.

Aia 1,977 Nearly a Posting Maven

Compiler errors are compounded. The first error creates another and another, and so on.

For example: I see that you use a variable named c a few lines
below main, but you never declared that variable.
p and q suffers the same problem. Fix those and things start looking better.

you prototype:
void copy_back (char b1, char b2);
However you use it as:
copy_back();
You did not pass any argument, and it needs two.

void display_fctn (char b1, char b2); has the same problem.
Ckeck all arguments in the functions.

Aia 1,977 Nearly a Posting Maven

Getta rope Nope, too expensive.

Aia 1,977 Nearly a Posting Maven

Hi all,

I just started to work C++ in Dev C++ compiler before that i used Turbo C++ compiler when i try to compile a simple program in Dev C++ compiler . I'm getting error .

Here's the program

#include <iostream>
#include <conio.h>

int main ()
{
 cout << "Hello World";
 getch();
 return 0;
}

I'm getting following error .

implicit declaration of function `int getchar(...)'

Please tell me what the problem with that code .

Thanks in advance

Dev C++ doesn't know about #include < conio.h>
getch() is why conio.h is needed.
change getch for getchar and it will not complain. You do not need conio.h.

Aia 1,977 Nearly a Posting Maven
#include<stdio.h>

int main(void)
{
    char string[50];
    char *ptr = string;

    printf("Enter string\n");
    fgets(string,sizeof string,stdin);

    printf("string= \"%s\"\n",string);

/* first letter of string */
    *ptr = toupper(*ptr);

/* going thru string */
    while(*ptr)
    {
        if( isspace(*ptr) )
        {
            *(++ptr) = toupper(*ptr);
        }
        ++ptr;
    }
    printf("The new string is %s",string);
    
    getchar();
    return 0;
}
Aia 1,977 Nearly a Posting Maven

You have a lot of illegal code in you program. Basically anything where you deal with pointers you use them illegally. We'll call the police. :)
For example:

title[++i]=*cPtr;
    fname[++j]=*cPtr;
    lname[++k]=*cPtr;
    
    price[++l]=*cPtr;
    repcost[++m]=*cPtr;

    title[p] = tolower(title[p]);
    if(title[p]==lookup_field[p])

I am going to guess, here, that the confusion is how you look at pointers.
For example:

char *title[ 20 ];

This is not a pointer to a string. It isn't the same that char *title = string, where string is a char string[20];

char *title[ 20 ] is an array of pointers. Meaning you are declaring 20 char *title, and
each one can point to a different string or a char happy_string[].

Therefore:

title[ ++i ] = *cPtr;

will never work.

Neither

title[p] = tolower( title[ p ] );

The function tolower acepts an integer as a parameter and you are passing to it a char * pointer to a string.

Aia 1,977 Nearly a Posting Maven

Why does that function say its return int * when it is in fact returning char * ?

The habit of writing int all the time. Yes it should be char *

Aia 1,977 Nearly a Posting Maven

Here is the SAMPLE.C where gets() works absolutely fine. I dont understand why it isnt working in PROGRAM.C

#include<errno.h>
#include<stdio.h>

int getline(char line[], int max)
{
int nch = 0;
int c;
max = max - 1;            /* leave room for '\0' */

while((c = getchar()) != '\0')
    {
    if(c == '\n')
        break;

    if(nch < max)
        {
        line[nch] = c;
        nch = nch + 1;
        }
    }

if(c == EOF && nch == 0)
    return EOF;

line[nch] = '\0';
return nch;
}


#include <stdio.h>

extern int getline(char [], int);

main()
{
char line[256];

printf("Your names");
getline(line,256);
//while(getline(line, 256) != '\0')
  //
    printf("you typed \"%s\"\n", line);

return 0;
}

I tired the solution posted by geek ANCIENT DRAGON. It is not working too....:

char line[100];
fgets(line,sizeof(line),stdin);

Take a look at this function:

#include <stdio.h>

int *getline( char *string, size_t size )
{
    size_t i = 0;
    for(;;)
    {
        int ch = fgetc(stdin);
        if(ch == '\n' || ch == EOF)
        {
            break;
        }
        if(i < size - 1)
        {
            string[i++] = ch;
        }
    } /* forever loop end */

    string[i] = '\0';
    return string;
}
Aia 1,977 Nearly a Posting Maven

>if the current number is larger than the previous one, it gets printed to screen, if not, it gets ignored

What happens if the current number is larger that the previous one, but
smaller than the one before the previous one? How would you know that?

Aia 1,977 Nearly a Posting Maven

thank you so much last question..
what does rewind ???

Are you refering to rewind()?.
rewind() is a file pointer (not the same that pointers) function. It reset
the file pointer back to position 0 at the start of the file. You deal with
file pointer when you work with random access files. Part of the functions in the tool box are fseek(), ftell() and rewind();

[Edit:] Sorry Ancient Dragon, I problably was still writing this when you posted.

Aia 1,977 Nearly a Posting Maven

>while((temp != -99) || (temp != 212));

change the || for a &&

Aia 1,977 Nearly a Posting Maven

No. Valid indices would be 0-2, for a total of 3.

So I always got it wrong (opposite) in my mind.
Thank you very much.

Aia 1,977 Nearly a Posting Maven

Nope, the dimensions which we specify at the time of declaration/definition are the actual dimensions of the array. Their indexing is 1 off of the dimensions.

Let's see if I finally get this correct for once:

int array[3];

array[0]
array[1]
array[2]
array[3]

Four elements in an a single dimention array.

int array[3][2];

array[0][0]
array[0][1]

array[1][0]
array[1][1]

array[2][0]
array[2][1]

Correct?

Aia 1,977 Nearly a Posting Maven

int arrayOfArrays[2][3] will make an array of 2 integer arrays of length 3 each. A 2x3 if you will.

Isn't an array of 3 integers of 4 elements each?

Aia 1,977 Nearly a Posting Maven

Hi
which it did, but still exits when I press enter; which is not ideal for programs which require it.
PC

I have a concern that you are "placing the carriage in front of the horses". I would encourage to keep learning and you will learn about flow control top-down. Then you will know how to ask the program to
stop when it needs to and when to loop, etc...

Right now you are experiencing the flickering in the screen because that's what you are telling it to do. Nothing else.

The getchar() function, all that is suppost to do is to read a character from the standard input buffer.
By using it you take avantage of that, "making it to wait" to let you see what the program has input to screen.

The time will come when you will have to do more "productive things", that to display text in the screen. Then what Ancient Dragon told you would be part of the ways you'd have control over the program behavior.

Aia 1,977 Nearly a Posting Maven

I have a two dimensional array that I need to make into a global variable to be able to access it from other functions. I can't quite figure out what the correct syntax is.

Put them any where before the main function. Kind like the same way
you put prototypes of functions before main.

By the way, void main should be int main(void)

Aia 1,977 Nearly a Posting Maven

I'm haven't took array yet :'(
can you write it on while loop

but you specified the numbers, what if i want to enter nth number ?

Could you at least show me what you have tried so far?. I think I have
writen too much of you assigment. I'm trying to help you to get these
concepts, but sorry I want you to try and learn.:-|. You should at least
know how to create the function to check for even numbers. Also you should
know already how to call that function inside a while loop, and how to
ask for a number from the use inside that loop.

Aia 1,977 Nearly a Posting Maven

Do I need to insert While for loop on Q4 ?

last question, pls

That depends how you want to get the integers to be analized.
You can write a while loop asking to enter an integer every time until the user enters a sentinel or a stablished preselected key that will stop the loop. Or if you declare an integer array of selected numbers, you could use a for loop. The code below is a example of the latest:

#include <stdio.h>

int even(int integer)
{
    return(integer % 2 == 0);
}

int main(void)
{
    int i;
    int numbers[] = { 55, 66, 76, 45, 2, 4, 3 };
    
    for(i = 0; i <= 6; i++)
    {
        if(even(numbers[i]))
        {
            printf("%d is even\n", numbers[i]);
        }
    }
    getchar();
    return(0);
}
Aia 1,977 Nearly a Posting Maven

Give me more explaination, pls

You will have to modified for C++ in the main fuction, but this is
how I would do it in C

#include <stdio.h>

int check_it(int n1, int n2)
{
    return(n1 % n2 == 0);
}

int main(void)
{
    int num1 = 10;
    int num2 = 2;
    
    if(check_it(num1, num2))
    {
        printf("%d is a multiple\n", num2);
    }
    else
    {
        printf("%d is not a multiple\n", num2);
    }
    
    getchar();
    return 0;
}
Aia 1,977 Nearly a Posting Maven

It gave two condition either true or false (1 or 0) then....

Have you tried this in a function?:

return( first_number % second_number == 0 );
Aia 1,977 Nearly a Posting Maven

hi

can anyone tell me what do we mean by:

system( "PAUSE" );

and

system( "CLS" );


in C++

thanks

system("PAUSE"); the program waits for you to enter a key
system("CLS"); clears the console or command line terminal

both of makes your program not portable since is operating system
depended

Aia 1,977 Nearly a Posting Maven

Thanks I appreciate it

You're welcome.

Now if you are pushing for more nested for loops, you could always get one more loop in the nest.

#include <stdio.h>

int main(void)
{
    int a,b,c;
    
    for(a = 0; a < 5; a++)
    {
        for(b = 1; b <= 8; b++)
        {
            for(c = b; c <= 8; c++)
            {
                printf("%d", c);
            }
        putchar('\n');    
        }

    }
    getchar();
    return 0; 
}
Aia 1,977 Nearly a Posting Maven

yes the output is expected to look like that.

This could be one of many ways of doing it. Take a look at it. Look also at the format for posting code.

#include <stdio.h>

int main(void)
{
    int a = 1;
    int b = 0;
    int c = 8;
    
    for(a = 1; a <= 5; a++)
    {
        for(b = a; b <= c; b++)
        {
            printf("%d", b);
        }
        c++;
        putchar('\n');
    }
    getchar();
    return 0; 
}
coldfire101 commented: Simple n clean program.i'm just starting in 'C' programming and been havin a real tough time figuring out nested loops.....guess this'd be givin me a headstart.Thank you. +0
Aia 1,977 Nearly a Posting Maven

Please help I'm trying to write a program in C using nested loops which has an output of 1-8 (newline) 2-9 (newline) 3-10 (newline) 4-11(newline) 5-12. I wrote a program but I know it has to be a simplier way and I don't think I used nested loops correctly because the first for statement is irrilevant. PLEASE HELP


[

Is the output expected to look like this?:

12345678
23456789
345678910
4567891011
56789101112

I am having trouble understanding your question.

Aia 1,977 Nearly a Posting Maven

Hi Edited the question once. Not changed in over an hour.

The first time you original question was about a specific line error that you had. You wrote:

Again = ReadCharPr("Test another number (y/n)? "); //statement missing here?

Second time you question was edit again and also you included this:

while (Index*(Index+1) < 2*Number)
    {
      Index = Index + 1; //'i' was used rather than index here
    }
    if  (Index*(Index+1) == 2*Number) //the correct 'is equal to' was not used
      WriteStringCr("Triangular");
    else
      WriteStringCr("Not triangular"); //the semicolon here was not included
    Again = ReadCharPr("Test another number (y/n)? ");

And after that you edited the question to:

Can anyone spot the semantic error in this triangular number calculator here? It correctly reports 21 as being a triangle number but incorrectly that 15 is not a triangle number. However if you input 15 as the first value entered it correctly says that 15 is a triangle number!!

No desire to start a war of words here. But like I say. You want help,
you will get help here, however editing post to different questions are
confusing.

Aia 1,977 Nearly a Posting Maven

You keep editing your original question. Is is very confusing. You has changed you question three times.

Aia 1,977 Nearly a Posting Maven

I guess I'm not understanding what your saying.
Where did you change the Index = 1 to?.

... Is it working now?.
Could you post your changes?.

Aia 1,977 Nearly a Posting Maven

Index = 1;
should be inside the outer while loop.

I'm afraid that is not correct. Index is a counter and is ok were is being declared.

Aia 1,977 Nearly a Posting Maven

Can anyone spot the semantic error in this triangular number calculator here?

ReadIntPr("Enter number for testing: ");
WriteStringCr("Triangular");
Again = ReadCharPr("Test another number (y/n)? ");

}

Are you including the proper #defines at the beginning of the source file?.
Are you providing the proper prototypes for those functions.
Did you include those functions?.

Aia 1,977 Nearly a Posting Maven

why oh why did I ever post in that thread...

Don't bit yourself up, you couldn't help it.;)

Aia 1,977 Nearly a Posting Maven

Yes. It's more convenient than a pointer, and much safer, because you don't have to worry about accidentally mispointing it.

Thank you. Much appreciated.

Aia 1,977 Nearly a Posting Maven

>What are you trying to do passint as a parameter int& tms?
It's a counter. If it wasn't passed as a reference, it wouldn't update because the variable would be a copy of the original.

Mister Joeprogrammer,
Am I correct, then, in assuming that this way of reference in a function is something different for C++ than for C? I know you can not do it in C, but my C++ is very limited.

Aia 1,977 Nearly a Posting Maven

i have tried to change it

int i;
double D_Nath[11],D[11],er[11];
for( i=0;i < 11; i++)
{
D_Nath(i)=PI*D(i)/er(i)*.76554;
}

this is what I have for the code but I am getting a C2064 error in the line with the D_Nath(I)=
any idea what I am doing wrong

D_Nath[i]=PI*D[i]/er[i]*.76554;

You forgot to change the () for [] inside statement inside the loop

Aia 1,977 Nearly a Posting Maven


.\pa2-q1.cpp(59) : error C2062: type 'bool' unexpected
.\pa2-q1.cpp(60) : error C2143: syntax error : missing ';' before '{'

The first line I think is because in the prototype you have the first
parameter as an int and in the actual function is a int array.

I always copy my function and use it as a prototype, just adding the ; and the end.

The second error I can not see any missing ; any where. Are you sure that your posted copy is the same you are compiling. In my compiler after fixing the little mispells I don't have those errors.
I have other errors, but will get there... :lol:


What are you trying to do passing as a parameter int& tms?

Aia 1,977 Nearly a Posting Maven

Can anyone tell me why I'm getting build errors on the actual function heading and the line under it (**) saying "type bool is unexpected" and that I'm missing a ; before {? I've looked and can't find anything.

Also, I get this error but there is no line 80 and all my braces match up (I think):
pa2-q1.cpp(80) : fatal error C1075: end of file found before the left brace '{' at '.\pa2-q1.cpp(17)' was matched


Any help is appreciated! :confused:

bool Bsearch (int , int , int , int, int&);

bool Bsearch (int chart[], int find, int start, int end, int& tms)

remove the & after the last int in the bool Bsearh fuction

else
{
//bool found=0
if (Bsearch(chart[MAX_ITEMS],find,start,end,tms))
cout<<"Your number was found in the list after "<<tms<<" passes."<<endl;
else
cout<<"Your number was not found in the list after "<<tms<<" passes."<<endl;

cout<<"Search for another number? Enter 1 for Yes or 0 for No: ";
cin>>cont;
} while (cont);

_getch();
return 0;
}

You are missing an ending bracket for the first else. The one right after while belongs to the do/while loop.

Aia 1,977 Nearly a Posting Maven

o ya your right thats weaird my computter calculator is messed up or something o waite lol no i was doing a logarithmic function i think

Yeah, it helps to know what you want to do, first. :)

Aia 1,977 Nearly a Posting Maven

What you are doing is:

2^5 = 2 * 2 * 2 * 2 * 2 = 32
That is correct.

#include <iostream>
#include <math.h>

using namespace std;
int main()
{
float a,b,c;
a=0;
b=0;
c=0;
cout<<"enter base"<<endl;
cin>>a;
cout<<"enter power"<<endl;
cin>>b;
pow(a,b); /* you don't need this here */
c = pow(a,b);
cout<<c;
 
system ("pause");
 }
Aia 1,977 Nearly a Posting Maven

so like this?

What I meant was:

Declare another float or better yet a double variable at the begining of
main. Then assign the result of the pow function to that variable.

Then do what you wish with that result that is in the variable. :)