Crazy Answers - Please Help!
Tune up your compiler''s warning level. VC6 above should give a ''variable used without being initialized'' or something like that on the code (dunno about other compilers).
I would also make your count var a double. Or a long int. As if you add up all the things inbetween 0 and max(int) you will wrap.
quote:Original post by Cmutt1974
C++ Primer Plus is a book for people who have programed before. Its not really a beginners book. I have C++ Primer Plus, and I had a problem with the same question, but I solved it myself. You should get a book on C also. Arrays, Loops, Pointers, functions are all C stuff, and C books do a good job of explaining this features. Actually you should master them. You need to get a book that explains everything, and more up to date book. Keep C++ Primer Plus the author writes very well, but he assumes you know a lot because its not a beginners book, but get a beginners book also. Someone told me its good to have several books, because one author may explain something better than another. Not many people can explain all of C++ effectively.
Actually, I have been learning C for awhile now... about 6 months. The only problem is that I had not had a book, so I was trying to learn from th many poorly constructed online tutorials that, for the most part, just say: this (*) is a pointer. Use it. I bought this book (along with aquiring a few other older books) to increase my learning and get my C++ programming off the ground.
quote:Original post by Cmutt1974
C++ Primer Plus is a book for people who have programed before. Its not really a beginners book. I have C++ Primer Plus, and I had a problem with the same question, but I solved it myself. You should get a book on C also. Arrays, Loops, Pointers, functions are all C stuff, and C books do a good job of explaining this features. Actually you should master them. You need to get a book that explains everything, and more up to date book. Keep C++ Primer Plus the author writes very well, but he assumes you know a lot because its not a beginners book, but get a beginners book also. Someone told me its good to have several books, because one author may explain something better than another. Not many people can explain all of C++ effectively.
Actually, I have been learning C for awhile now... about 6 months. The only problem is that I had not had a book, so I was trying to learn from th many poorly constructed online tutorials that, for the most part, just say: this (*) is a pointer. Use it. I bought this book (along with aquiring a few other older books) to increase my learning and get my C++ programming off the ground.
Ok, one more question now...
How do you dynamically create a new array of structures?
Here is what I did...
Don't laugh... I'm sure I have plenty of errors in there.
Edit: Now the program runs smoothly, except it skips the part to enter in the make - it just goes straight to the year.
[edited by - PepsiPlease on October 2, 2002 7:26:51 PM]
[edited by - PepsiPlease on October 2, 2002 7:33:12 PM]
[edited by - PepsiPlease on October 2, 2002 7:35:06 PM]
How do you dynamically create a new array of structures?
Here is what I did...
struct car //The structure car{ char make[20]; int year;};//...car * cars[numcars] = new car; //create array of structures //Whenever I try this it compiles fine, but then upon execution just skips the whole program and goes to the end. //Anyway, here is the full code: #include <iostream>using namespace std;int main(){ int numcars = 0; struct car { char make[20]; int year; }; cout<<"How many cars do you wish to catalog? "; cin>>numcars; car * cars = new car[numcars]; for (int a = 0; a < numcars; a++) { cout<<"\nCar #"<<a + 1<<":\n"; cout<<"Please enter the make: "; cin.getline(cars[a].make, 20); cout<<"\nPlease enter the year: "; cin>>cars[a].year; } cout<<"\n\nHere is your collection: \n"; for (int b = 0; b < numcars; b++) { cout<<cars[b].year<<" "<<cars[b].make<<endl; } delete [] cars; return 0;}
Don't laugh... I'm sure I have plenty of errors in there.
Edit: Now the program runs smoothly, except it skips the part to enter in the make - it just goes straight to the year.
[edited by - PepsiPlease on October 2, 2002 7:26:51 PM]
[edited by - PepsiPlease on October 2, 2002 7:33:12 PM]
[edited by - PepsiPlease on October 2, 2002 7:35:06 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement