tux4life 2,072 Postaholic

>Secondly... how do you return several values with a function?
return val1, val2;

This isn't possible, but you can use a structure (struct) to do something equal:

struct multiple_vars {
    int a;
    int b;
    int c;
};

multiple_vars add(int n1, int n2)
{
    multiple_vars result;
    result.a = n1;
    result.b = n2;
    result.c = n1+n2;
    return result;
}
tux4life 2,072 Postaholic

And now why you write:

do {
/* Code here */
} while ([B]expression[/B]);

A declaration in a condition introduces a name to be used in the following statement; the condition in a do-while has the statement before the condition, so declarations make no sense there (and are disallowed).

WaltP commented: Good job!!! +19
tux4life 2,072 Postaholic

Can you please post your whole code?
It's easier for me to find the error then :P

tux4life 2,072 Postaholic

It would be helpful to me if you posted the whole code (using code tags) you were trying to compile (if your question isn't already solved yet) ...
Probably you forgot to type a ';' somewhere in your code :)

tux4life 2,072 Postaholic

I sent a mail to Bjarne Stroustrup and asked him: What's the difference between a condition and an expression (in C++) ?

I'm quoting his whole reply:

What's the difference between a condition and an expression in C++ ?
A condition is something you test in an if, while, for, or switch statement.

A condition can be an initialized declaration or an expression:

if (a==7) // the condition is an expression

if(int a = f(x,5,y)) // the condition is a declaration

tux4life 2,072 Postaholic

To the OP: if([B]condition[/B]) : condition is the expression being evaluated, if the evaluated expression has a value other than zero, the condition is true , otherwise the condition is false ...

This also applies to your while and do-while question :)

tux4life 2,072 Postaholic

Never said so. I was not commenting on const vs. #define . It was the enum/#define comment that prompted my response -- and the silly keystroke comment therein..

Sorry, I must have misinterpret your post :(

tux4life 2,072 Postaholic

true is a conditional expression, so there was nothing wrong with my example, BTW: don't they always say that a condition can be true or false ?

>int a; is an expression because there is an assignment to the variable a . See through it? It is the default value or an unknown value which is assigned to a , which can be int a = 3287; or whatever. Still assigning.

Wrong! An assignment is a statement, the value you're assigning is an expression, in other words: on the right side of the assignment operator '=' there always has to be an expression !

>You cannot have an expression in your code as this: 1 + 1 , without assigning it to a variable though in algebra this is an expression.

Completely wrong! 1+1 is a valid C++ expression, don't you believe me?
Try compiling the following code:

#include <iostream>

using namespace std;

int main()
{
    [B]1+1;[/B] // -> The "impossible" expression you were talking about
    return 0;
}

>I'm sorry for being too pathetic. I'm just proving my point.

No, you're just proving that you're wrong.

tux4life 2,072 Postaholic

>Condition on the other hand is a comparison
Wrong! A condition is not necessarily a comparison: if(true) cout << "Where is the comparison?" << endl; >an expression is an assignment to a variable like ...
Wrong again! An assignment is a statement, I would describe an expression as something which has a value and can be passed to a function :)

But you can say that (a=10) is an expression in the following context:

int a;
int b = [B](a=10)[/B];
tux4life 2,072 Postaholic

Hence,


Here's a perfectly good if statement:

if ((2*x)+7)
{
   ...
}

Is this considered a condition or expression? As I say, stop getting hung up on vague definitions of words.

I think this is considered as a conditional expression :P (check this)

tux4life 2,072 Postaholic

AAMOF I find it faster to do the #defines because of cut/paste. It takes 13 keystrokes for me to get

#define
#define
#define
#define
#define

Then add the definitions from the bottom up. Much faster.

Is that a reason to avoid using the const keyword? I don't think so ...

BTW, If you take the same approach, but with const instead of #define it will even save you more keystrokes :P

tux4life 2,072 Postaholic

That's why you are supposed to wrap them in brackets.

#define A 10
#define B 20
#define C (A + B)
int result = 2 * C; // will give 60

I know, but if you do the same, with constants declared with const for example, you don't have to bother with braces :)

tux4life 2,072 Postaholic

enum method saves keystrokes and is more understandable IMO.

Oh, right I forgot about that, and another addition: #define is deprecated for constants:

#define A 10
#define B 20
#define C A+B
int result=2*C; // won't give 60 as output
tux4life 2,072 Postaholic

Try compiling with: g++ fig03_17.cpp Gradebook.cpp :)

WaltP commented: Good Catch +19
Nick Evan commented: I agree +17
tux4life 2,072 Postaholic

If you have been on MSN.com you may have already seen this video. Its a tutorial on how to cut down a tree :)

I've tried it :P

tux4life 2,072 Postaholic

In modern C++ condition is not the same thing as an expression. A condition can be a declaration, that's an example from the Standard:

int i = 1;
while (A a = i) {
//...
i = 0;
}

Can you give an example from the standard for an expression as well?
So we can compare :)

tux4life 2,072 Postaholic

Oops!! soory dude!! my bad..nyways thanks for helping me

Never mind, I would find it strange that a teacher asks you things on your exam, where you don't have any notes of :P

tux4life 2,072 Postaholic
enum {
  JANUARY = 1, FEBRUARY, MARCH, APRIL;
};

I think you aren't much with an enumeration like this, if your enumeration (the data type) hasn't got a name, then you should declare a 'variable' directly after it's definition (you don't have to do this, syntactically your example is correct, but if you don't do this it's pretty much useless: you could just leave it's declaration out of your code because you cannot use it, because you've no instance of it)

tux4life 2,072 Postaholic

Sorry, I forgot to place a semicolon after the closing brace
on my examples...Sorry too for multiple posts.

Then just edit your post :)

tux4life 2,072 Postaholic

I think you haven't read this carefully enough:

BTW, I think your teacher's intention is that you look it up in your course

Have you tried to look it up in your course before starting this thread?

tux4life 2,072 Postaholic

That may be true, but you've to understand the answer we're giving to you, just learn everything by heart is not right the way to become a successful C++ programmer, you really have to understand what you're doing :)

BTW, I think your teacher's intention is that you look it up in your course :P

tux4life 2,072 Postaholic

Did you select 'C Project' in the 'New Project' Dialog ?
Otherwise reinstalling Dec-C++ might solve the problem :)

tux4life 2,072 Postaholic

Example I:

int array[5];
int el;
el = array[5]; // out of bound
el = array[6]; // out of bound

Example II:

int array[5];
int *p, el;
p = array;
el = *(p+5); // out of bound
el = p[7]; // out of bound
tux4life 2,072 Postaholic

Example of a structure:

struct book {
    char title[25];
    char author[25];
    char publisher[25];
    int price;
};


Example of an enum(eration):

enum book {
    BIG,
    SMALL,
};
tux4life 2,072 Postaholic

Can you please post the code you're trying to compile?

tux4life 2,072 Postaholic

Oh well..you asked for it.

Actually there's no need for rapidshare, and if you've big code you can always attach your source to this thread :)

tux4life 2,072 Postaholic

I dont know if I did, I dont think so :-O

Try to do it :)

tux4life 2,072 Postaholic

Visual C++ Projects
To change the build output directory:
1. On the Project menu, click Properties.
2. Expand the Configuration Properties tab, and click General.
3. Change the Output Directory box to the new output directory.

BTW, Did you put the path(s) between quotes?

tux4life 2,072 Postaholic

Go to: Build>Configuration Manager Edit:: Sorry, I didn't read your question thoroughly :(

tux4life 2,072 Postaholic

In a do-while statement the condition is always evaluated at the end of the loop which means that the loop is always at least executed one time :)

tux4life 2,072 Postaholic

A condition is something which is brought down to be true or false .
Most of the time, an expression can be evaluated to be true or false , false stands for the value 0 and true stands for all the other possible values :)

tux4life 2,072 Postaholic

why am I using getch() a function i never used before again?

I didn't say you have to use it, it's only a suggestion :(

tux4life 2,072 Postaholic

So what does Compilers have to do with anything?

Now I know you're using MinGW, I also know you can use getch() as I'm using MinGW myself :)

tux4life 2,072 Postaholic

The only C++ compiler out there?
Bloodshed

That's not the only one, to be 100% correct: Bloodshed isn't a compiler, you mean MinGW, which is part of the Bloodshed Dev-C++ IDE :)

Other compilers are: Digital Mars, MSVC++, Borland, DJGPP, and much more :)

tux4life 2,072 Postaholic

What compiler are you using?

tux4life 2,072 Postaholic

To remember for ever: DaniWeb isn't a homework completion service, that means that we aren't writing this program for you, show us what you've already done so far, tell us where you get stuck and ask specific questions about the things you don't understand, all what you've done so far is being lazy and posting your assignment in a thread :(

tux4life 2,072 Postaholic

Siddhant3s, we're in the C forum here :P

tux4life 2,072 Postaholic

We are giving you a dynamic solution, the only problem is that you aren't accepting it :(

tux4life 2,072 Postaholic

Oh sorry, I think I know what you mean: You want to open a notepad file in notepad without a command line popping up ...

tux4life 2,072 Postaholic

>>I need to know a way to open a notepad document from one of my programs without opening a console window.
>>Oh, by the way tux4life, I don't want to open it for i/o. I just want the user to be able to read it. It's kind of like a help file.

You cannot read a file without using I/O techniques :P

Actually you need I/O (but only the input part then): you have to read out the notepad document and display it on the screen right?

tux4life 2,072 Postaholic

>>is it possible to return class A's struct in some function to class B?
Yes

>>do i need to overload this? and if so how would i write the overload function?
No, you've to make class B a friend class of A

tux4life 2,072 Postaholic

Write and compile it as a Windows program (without a window), you could use the fstream classes for file I/O :)

tux4life 2,072 Postaholic

Can i use the call cin.ignore('/n')?

First of all it is cin.ignore('[B]\[/B]n'); and secondly: read this ...

tux4life 2,072 Postaholic

>i am interested in looping structure..
There are plenty of C tutorials on the internet, just use Google to find them :)

tux4life 2,072 Postaholic

>I think you are talking about your this post: blablabla
No, I was talking about the 7th and 8th post of this thread :) (and of course also the post you thought about)

Edit:: If you combine these posts you'll be able to create such a program ...

tux4life 2,072 Postaholic

but i was asking when my array
int arr[] = {10,20,30,40,50,60,70,80,90,100};
or

int arr[] = {10,20,30,40,50,60,70,80,90,100,10,20,30,40,50,60,70,80,90,100};

For this how to write the code so i got the output..

I already addressed this in one of my previous posts :)

Edit:: Ah, now I understand what you meant with: 'how to make this dynamic'

tux4life 2,072 Postaholic

Because the file apparently contains the binary (or computer internal storage) values of the data, which are not human-readable and not text. Such files can not be opened in text mode.

Yeah, I know but I just find that a bit clumsy, if the numbers are stored a non-human-readable text you'll have to use a conversion program to insert data into a file, before you can use this file with this program :)

Edit:: I actually meant that you could also use the text mode for this purpose (reading some numbers from a file, take the absolute value from it and write it (=the absolute value) back to another file)

tux4life 2,072 Postaholic

>but problem is how to make this dynamic??
or display all numbers
I don't understand that, can you give me an example of this?

BTW, your code is in C, though it's valid C++ code the C++ way of I/O is preferred over the I/O from stdio.h Another remark: maybe your compiler isn't complaining about this (in this case you're probably using a dinosaur compiler): main() has to be int main() , the main function always has to return a value :)

Edit:: Sorry siddhantes I didn't see your post

tux4life 2,072 Postaholic

For the third part:

10+20+30 => all elements except the last one
10+20+40 => all elements except the one before the last one
20+30+40 => all elements except the first one
10+20+30+40 => all elements

:)

tux4life 2,072 Postaholic

To achieve the next milestone in your program (:P) the following might help you:

10+20
10+30
10+40
20+30
20+40
30+40

You've to run the loop three times (the number of elements in the array decreased by one)
Every time you display all the elements coming after the element, so if you've 10, you're displaying each time 10+ '20,30,40', for 20 it's the same: 20+ '30,40', and so on :)