|
-
Jan 6th, 2003, 01:36 PM
#1
Thread Starter
Frenzied Member
Dev C++ not compiling
#include<iostream>
inline float cube(const float s) {return s*s*s;}
int main() {
float side;
cin >> side;
cout << "Volume of cube with side" << side<< "is "
<< cube(side) << endl;
return 0;
}
Shouldn't that compile? I can't compile anything!! I just downloaded the new version today and it does the same thing as the old. I can't compile. Am I missing something?
-
Jan 6th, 2003, 01:59 PM
#2
Monday Morning Lunatic
You're missing a using namespace std; in there.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 6th, 2003, 02:05 PM
#3
Thread Starter
Frenzied Member
Didn't learn about those yet. If that is object oriented, I haven't even touched it yet.
What should I type in?
-
Jan 6th, 2003, 02:11 PM
#4
Simply add the line
using namespace std;
after all your includes.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 6th, 2003, 02:24 PM
#5
Thread Starter
Frenzied Member
#include<iostream>
using namespace std;
inline float cube(const float s) {return s*s*s;}
int main() {
float side;
cin >> side;
cout << "Volume of cube with side" << side<< "is "
<< cube(side) << endl;
return 0;
}
Still didn't work.
-
Jan 6th, 2003, 02:27 PM
#6
Frenzied Member
I always like to call namespaces some sort of collections of functions, nicely ordered in different namespaces.
In this case, it's about the std namespace.
Normally you would type
Code:
#include<iostream>
inline float cube(const float s) {return s*s*s;}
int main() {
float side;
std::cin >> side;
std::cout << "Volume of cube with side" << side<< "is "
<< cube(side) << endl;
return 0;
}
The std:: indicates that the function you're going to call is in the std namespace.
Now the using namespace ... means that the compiler assumes those functions are in the std namespace.
so:
Code:
#include<iostream>
using namespace std;
inline float cube(const float s) {return s*s*s;}
int main() {
float side;
cin >> side;
cout << "Volume of cube with side" << side<< "is "
<< cube(side) << endl;
return 0;
}
Would work since the compiler knows those cin and cout are in the std namespace.
I hope I clarified things a bit!
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 6th, 2003, 02:30 PM
#7
Thread Starter
Frenzied Member
It still does not compile.
-
Jan 6th, 2003, 02:31 PM
#8
Frenzied Member
What errors do you get than my friend? going to eat now but I'm sure there are other people that are able to help you out!
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 6th, 2003, 02:33 PM
#9
Thread Starter
Frenzied Member
Compiler: Default compiler
Building Makefile: "D:\Program files\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "D:\Program files\Dev-Cpp\Makefile.win" all
g++.exe -c Templates/main.cpp -o Templates/main.o
Templates/main.cpp:1:20: iostream: No such file or directory
Templates/main.cpp: In function `int main(int, char**)':
Templates/main.cpp:9: `cin' undeclared (first use this function)
Templates/main.cpp:9: (Each undeclared identifier is reported only once for
each function it appears in.)
Templates/main.cpp:10: `cout' undeclared (first use this function)
Templates/main.cpp:11: `endl' undeclared (first use this function)
make.exe: *** [Templates/main.o] Error 1
Execution terminated
-
Jan 6th, 2003, 03:24 PM
#10
Is this the newest available version of DevC++? If not, get the newest. If yes then your include paths are probably set up incorrectly. I'm sure someone here can help you with that (I've never used DevC++).
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 6th, 2003, 03:30 PM
#11
Thread Starter
Frenzied Member
Isn't there a standard that compilers follow.
-
Jan 6th, 2003, 04:15 PM
#12
Hyperactive Member
The latest version 5 is still in beta, I believe.
Maybe it is a bug or something.
That's why I'm still using version 4.
-
Jan 6th, 2003, 04:55 PM
#13
Standard in what way? C++ and it's libraries are standardized, the include paths are not.
And the standard changed a few years ago, so older compilers don't know the <iostream> header.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 6th, 2003, 05:26 PM
#14
Thread Starter
Frenzied Member
I should not have an old compiler. It is Dev C++ beta 5.
-
Jan 6th, 2003, 06:21 PM
#15
Frenzied Member
Maybe you should try degrading to version 4 as transcender is doing? Check if that helps..
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 6th, 2003, 10:01 PM
#16
Thread Starter
Frenzied Member
I have 4 now but I am having another problem. It does not seem to recognize endl; or setw (5); Here is the whole thing: It compiles with no errors but does not display right.
#include <cstdlib>
using namespace std;
#include <iostream>
using namespace std;
#include <iomanip.h>
using namespace std;
int main(){
const int R=10, F=11;
int responses [R]={1, 4, 6, 4, 8, 2, 6, 1, 8, 4};
int frequency [F]={0};
for (int answer=0; answer < R; answer++)
++frequency [responses[answer]]; // This is the key to it all!!!
cout << "Number" << setw(18) << "Frequency" << endl;
for (int rating=1; rating < F; rating++)
cout<< rating << setw(11) << frequency[rating] << endl; system("PAUSE"); return 0;}
Last edited by aewarnick; Jan 6th, 2003 at 10:42 PM.
-
Jan 7th, 2003, 12:01 AM
#17
Thread Starter
Frenzied Member
I found out what was wrong: I needed this as main arguments:
int argc, char *argv[]
What are they?
-
Jan 7th, 2003, 06:56 AM
#18
First, iomanip too is one of the standard headers, so it should be <iomanip>. <iomanip.h> and <iostream> don't work together.
Well, if you call an app like this:
myapp hello there -version -verbose
then you are passing command line arguments. Those arguments are in argc and argv. argc is the number of arguments and argv are the actual arguments. In this case argc would be 5 and argv would be
{"myapp", "hello", "there", "-version", "-verbose"}
because the actual program name is always included in the arguments.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 7th, 2003, 07:55 AM
#19
Monday Morning Lunatic
I think the supposed behaviour is for argv[0] to be the program name as it was invoked. For example, on a Unix system, if it is called via a symbolic link, or on any system if you gave it the pathname to the program, or whatever
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 7th, 2003, 09:10 AM
#20
Thread Starter
Frenzied Member
I guess I will learn more about that later.
Here is my problem now: I can't get that to break when a negative number is entered. Did I do something wrong?
for (int i=0; i<R; i++){
cin >> responses[i];
if (responses[i]<0) break;}
-
Jan 7th, 2003, 10:26 AM
#21
Please use [code][/code] tags when posting code and format it properly.
Code:
for (int i=0; i<R; i++) {
cin >> responses[i];
if (responses[i]<0)
break;
}
Looks ok to me. It doesn't break?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 7th, 2003, 10:44 AM
#22
Thread Starter
Frenzied Member
Now it breaks. Take a look at my other post about illegal operations. It came from there. All I changed was putting a limit in my arrays.
Would it be ok to use a letter instead of a number?
Last edited by aewarnick; Jan 7th, 2003 at 10:57 AM.
-
Jan 7th, 2003, 02:46 PM
#23
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 7th, 2003, 03:59 PM
#24
Thread Starter
Frenzied Member
this
cin >> responses[i]; if (responses[i]<=-1) break;
to this
cin >> responses[i]; if (responses[i]<=d) break;
-
Jan 7th, 2003, 04:10 PM
#25
Frenzied Member
try
Code:
cin >> responses[i]; if (responses[i]<='d') break;
please always post your code here inbetween code tags [code] Code here! [/code]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 7th, 2003, 04:17 PM
#26
I seldom use code tags for one line, and for multiple lines I already told him.
Whatever, you can do it, but the outcome won't be what you expect. A
int i;
cin >> i;
will only accept numbers as input, else cin will enter a fail state where it won't read anything anymore.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 7th, 2003, 09:30 PM
#27
Thread Starter
Frenzied Member
Ok, but I read in my book that letters have integer values and what does putting 'd' around d do?
-
Jan 8th, 2003, 04:16 AM
#28
Well, d would be a variable named d. 'd' is the letter d.
Yes, letters have integer values (their indices in the ASCII or other code tables). I said you could do it, but I said it wouldn't be what you expect.
I should rephrase.
int i;
cin >> i;
will only accept digits as input.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 8th, 2003, 11:06 AM
#29
Thread Starter
Frenzied Member
What you mean is that if I try to use the number value of a letter and trying to add that letter to a number it will not work but,
This line is ok though, right?
cout << "Enter d when finished. Next score: "; cin >> score[i];
if (score[i]==d ||!(score[i]<1000001)) break;
Last edited by aewarnick; Jan 8th, 2003 at 11:11 AM.
-
Jan 8th, 2003, 11:17 AM
#30
Frenzied Member
Is score a string? if it's an int it won't work as CB said...
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 8th, 2003, 11:36 AM
#31
No, the compiler will assume d is a variable. And if you write
'd'
then the user has to enter the ASCII code of 'd' in order to stop the loop.
Look, it's as simple as that:
int i;
cin >> i;
reads in the string representation of a number and then converts it to that number. So it might for example read in "123" and then convert that to the number 123. Look at the source code for the itoa function if you want to know how that works.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 8th, 2003, 12:12 PM
#32
Thread Starter
Frenzied Member
I made d a char and without the ' ' it works perfect. With them it loops endlessly. It did the same exact thing as an int with the ' ' but without them worked perfect.
But. . . as an int are you saying that if the user enters in d's # representation that it will inturpret it as d and break.
-
Jan 8th, 2003, 12:28 PM
#33
Code:
int i=0;
while(i != 'd')
{
cin >> i;
}
This loop will stop when the user enters
100
which is the ASCII code of 'd'
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 8th, 2003, 12:40 PM
#34
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|