Archived

This topic is now archived and is closed to further replies.

LegendNH

Can someone please tell me what is wrong with this code

Recommended Posts

It runs but for some reason it skips over every cinput statement except the first two: #include #include using namespace std; void main () { int number_of_students, a=0; cout << "How many names do you have to enter: "; cin >> number_of_students; //create dynamic array typedef int* intptr; intptr student_id; student_id = new int[number_of_students]; intptr midterm; midterm = new int[number_of_students]; intptr final; final = new int[number_of_students]; typedef char* charptr; charptr last_name; last_name = new char[number_of_students]; // for (a = 0; a < number_of_students; ++a) // { cout << "Students ID: "; cin >> student_idLink

Share this post


Link to post
Share on other sites
You''re trying to read up-to 8 characters into a single character. Try this:
  
// ...

char *last_name[8];
last_name = new char[number_of_students][8];
// ...

// At the end (before the end of main) you MUST have this:

delete [] student_id;
delete [] last_name;
delete [] midterm;
delete [] final;

Also, main is NOT allowed to have a return value of void. It must return an integer, and nothing else.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
it still does not work

That''s remarkably helpful. If you want more help, give more details. Also there''s a small typo in my last post: change "char *last_name[8];" to "char (*last_name)[8];". Other than that, it compiles and works for me. Good luck.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
quote:
Original post by mkoday
It would seem as though you are putting ++a as your 3rd statement in the for loop, when it should be a++.

They both work, it doesn''t matter as long as the increment isn''t within a statement that is based off of the intermediate value of the expression. For example:

int a = 5, b;
b = ++a;

The variable "b" is now equal to 6, and so it "a". However:

int a = 5, b;
b = a++;

The variable "b" is now equal to 5, and "a" is equal to 6.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
quote:
Original post by Null and Void

Also, main is NOT allowed to have a return value of void. It must return an integer, and nothing else.

[Resist Windows XP''s Invasive Production Activation Technology!]


Just wanted to point out that you should specify that it''s not allowed if you follow ANSI C standards but heck even my old college teachers used to teach us to use void main( void ) as the main function. But I agree with you, main should always return an integer....



"And that''s the bottom line cause I said so!"

** I WANT TO BE THE MODERATOR FOR THE LINUX FORUM **

Cyberdrek

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
Hash Bang Slash bin Slash Bash -- #!/bin/bash

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you should get in the habit of using ++a instead, because when using overloaded ++ operators on objects (such as iterators) the preincrement is faster. Both are equally fast on pointers and other basic types.

Share this post


Link to post
Share on other sites