GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Sep-2008, 17:49
qndy qndy is offline
New Member
 
Join Date: Sep 2008
Posts: 3
qndy is on a distinguished road

Re: Need help on a program for school


nice to meet you all.
i'm a newbie in this forum
i wanna ask something about C++

yesterday, i made a simple program using C++
the sintax are.

CPP / C++ / C Code:
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <time.h>

using namespace std;

int main (){
//pendeklarasian variabel dan array;
	int max;
	int jmlMrd;
	
	cout<<"Masukkan jumlah murid:";
	cin>>max;
	cout<<endl;
	
	char* murid[max];
	
	cout<<"Masukkan nama-nama murid:"<<endl;
//memasukkan nama
	for (jmlMrd=1;jmlMrd<=max;jmlMrd++) {
		cout<<jmlMrd<<".";
		cin>>murid[jmlMrd];
	}

	
	for(jmlMrd=1;jmlMrd<=max;jmlMrd++) {
		cout<<jmlMrd<<".";
		cout<<murid[jmlMrd]<<endl;
	}
	
	system("PAUSE");
	return 0;
}


when i compile it, there wasn't any problem
but when i fill the 3rd Array, it said "error"

can anyone help me?please
  #2  
Old 01-Sep-2008, 17:51
qndy qndy is offline
New Member
 
Join Date: Sep 2008
Posts: 3
qndy is on a distinguished road

Re: Need help on a program for school


anyway, sorry if the comments in my sintax are in Indonesian language.

because i'm an Indonesian
  #3  
Old 01-Sep-2008, 18:19
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Need help on a program for school


Quote:
Originally Posted by qndy
when i compile it, there wasn't any problem
but when i fill the 3rd Array, it said "error"
The size of arrays has to be defined at the time when the code is compiled. It appears that you believe that you can define the array's size at runtime. This is incorrect.

It is possible to dynamically create an array at runtime with functions such as malloc() & free() or operators new() & delete(), however you need to understand how these functions work. As I suspect you are just starting your study of C++, you will not see dynamic allocation discussed in coursework for several months. If you are curious to see how this works before then, either find the appropriate section in your textbook & begin reading it, or schedule time with your instructor to discuss the subject.

Since neither do I know your language nor the intent of your code, the following example can only approximate your original intention:
CPP / C++ / C Code:
#include <iostream>

using namespace std;

int main() {
    const int max = 80;
    char s[max + 1];
    int n;

    cout << "enter positive value < " << max << ":\t";
    cin >> n;
    if (n <= 0 || n >= max) {
        cerr << n << " is either not positive or is larger than " << max << endl;
        return 1;
    }

    for (int i = 0; i < n; i++) {
        cout << i << ":\t";
        cin >> s[i];
    }
    s[n] = '\0';

    cout << "string = " << s << endl;

    return 0;
}
Lastly, your question has no relation to the thread in which you have responded. You should have started a new thread.
Last edited by ocicat : 01-Sep-2008 at 18:52.
  #4  
Old 01-Sep-2008, 18:57
qndy qndy is offline
New Member
 
Join Date: Sep 2008
Posts: 3
qndy is on a distinguished road

Re: Need help on a program for school


sorry if my question has no relation to the thread.

ehm..i don't have any teacher or instructor to teach me about C++. It's hard to find programming teacher in my place.
My teacher of computer subject in my school doesn't know about C++.
So, I study it by myself.
Because of it, there are some subject that i can't understand well.
but, i will try harder to master it.

thanks for your reply.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
Arrays as function arguments - return arrays from functions pisuke C Programming Language 2 25-Jul-2007 12:03
Dynamic vs Static Arrays WaltP Miscellaneous Programming Forum 5 16-Feb-2006 16:54
I am reviewing Arrays and need help converting some strings to arrays jenmaz C Programming Language 22 23-Nov-2004 00:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:50.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.