473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

strings and arrays

hello everyone,i'm writing this program to enter a name and marks of a student and after that a message should pop out to say whether the student has passed or supplementing or repeating next year. this is what i did but i'm already giving it up coz i can't find the solution




#include<iostream>
#include<string>

using namespace std;
#include<iomanip>

void getInput(string & ,int&);
void displayResults(string [],int []);

int main()
{


int MarkP[15]={0} ;

string NameP[15]={0};

for(int x=1;x<=15; x++)
{
getInput(NameP[15],MarkP[15]);
displayResults(NameP[15],MarkP[15]);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{ cout<<"Enter the Name of the student\n";

cout<<"Name\t\tMarks\n";

cin>>NameP;
cout<<"\t\t";
cin>>MarkP;


}






void displayResults(string NameP[],int MarkP)
{
if(MarkP<=39)

cout<<"you failed the course and come next year to repeat\n";

if(MarkP>=40 && MarkP<=49)

cout<<"You may write the supplementary examination\n";

if(MarkP>=50 && MarkP<=74)

cout<<"Congratulations!!You passed the examination\n";

if(MarkP>=75 && MarkP<=100)

cout<<"You passes with a distinction\n";

if(MarkP>100)
{cout<<"The number you entered is in valid\n";
cout<<"Please choose a value between 0 and 100\n";
}
}



please help.
Aug 22 '07 #1
45 2008
r035198x
13,262 8TB
hello everyone,i'm writing this program to enter a name and marks of a student and after that a message should pop out to say whether the student has passed or supplementing or repeating next year. this is what i did but i'm already giving it up coz i can't find the solution




#include<iostream>
#include<string>

using namespace std;
#include<iomanip>

void getInput(string & ,int&);
void displayResults(string [],int []);

int main()
{


int MarkP[15]={0} ;

string NameP[15]={0};

for(int x=1;x<=15; x++)
{
getInput(NameP[15],MarkP[15]);
displayResults(NameP[15],MarkP[15]);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{ cout<<"Enter the Name of the student\n";

cout<<"Name\t\tMarks\n";

cin>>NameP;
cout<<"\t\t";
cin>>MarkP;


}






void displayResults(string NameP[],int MarkP)
{
if(MarkP<=39)

cout<<"you failed the course and come next year to repeat\n";

if(MarkP>=40 && MarkP<=49)

cout<<"You may write the supplementary examination\n";

if(MarkP>=50 && MarkP<=74)

cout<<"Congratulations!!You passed the examination\n";

if(MarkP>=75 && MarkP<=100)

cout<<"You passes with a distinction\n";

if(MarkP>100)
{cout<<"The number you entered is in valid\n";
cout<<"Please choose a value between 0 and 100\n";
}
}



please help.
1.) Never give up
2.) Use code tags when posting code
3.) Go through a basic tutorial on using strings in c++. Test the programs they give in that tutorial and then try your problem again. When you get stuck again, post in this thread both your attempt and the error messages that you get.
Aug 22 '07 #2
1.) Never give up
2.) Use code tags when posting code
3.) Go through a basic tutorial on using strings in c++. Test the programs they give in that tutorial and then try your problem again. When you get stuck again, post in this thread both your attempt and the error messages that you get.
my problem is my program only takes the first name not the last name,
Aug 22 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
my problem is my program only takes the first name not the last name,
Don't forget that cin>> stops on whitespace.

You might look up cin.getline() which can receive the entire line entered including all of the separate words.
Aug 22 '07 #4
Don't forget that cin>> stops on whitespace.

You might look up cin.getline() which can receive the entire line entered including all of the separate words.




#include<iostream>
#include<string>

using namespace std;
void getInput(string & ,int&);
void displayResults(string [],int []);

int main()
{


int MarkP[15]={0} ;

string NameP[15]={0};

for(int x=1;x<=15; x++)
{
getInput(NameP,MarkP);
displayResults(NameP,MarkP);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{ cout<<"Enter the Name of the student\n";

cout<<"Name\t\tMarks\n";

cin.getline(NameP);
cout<<"\t\t";
cin>>MarkP;


}
i tried to put that
cin.getline();
it is giving me another two errors that i don't understand.

please help
Aug 23 '07 #5
#include<iostream>
#include<string>

using namespace std;
void getInput(string & ,int&);
void displayResults(string [],int []);

int main()
{


int MarkP[15]={0} ;

string NameP[15]={0};

for(int x=1;x<=15; x++)
{
getInput(NameP,MarkP);
displayResults(NameP,MarkP);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{ cout<<"Enter the Name of the student\n";

cout<<"Name\t\tMarks\n";

cin.getline(NameP);
cout<<"\t\t";
cin>>MarkP;


}
i tried to put that
cin.getline();
it is giving me another two errors that i don't understand.

please help
i'm really desperate to get this right. i've tried but i'm really filing to get it right
Aug 23 '07 #6
ilikepython
844 Expert 512MB
#include<iostream>
#include<string>

using namespace std;
void getInput(string & ,int&);
void displayResults(string [],int []);

int main()
{


int MarkP[15]={0} ;

string NameP[15]={0};

for(int x=1;x<=15; x++)
{
getInput(NameP,MarkP);
displayResults(NameP,MarkP);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{ cout<<"Enter the Name of the student\n";

cout<<"Name\t\tMarks\n";

cin.getline(NameP);
cout<<"\t\t";
cin>>MarkP;


}
i tried to put that
cin.getline();
it is giving me another two errors that i don't understand.

please help
Ok for the getline, use this:
Expand|Select|Wrap|Line Numbers
  1. getline(cin, NameP);
  2.  
Also, you need a cin.ignore to eat the newline left by cin>>.
Expand|Select|Wrap|Line Numbers
  1. void getInput(string &NameP, int &MarkP)
  2. {
  3.     cout<<"Enter the Name of the student\n";
  4.     cout<<"Name\t\tMarks\n";
  5.  
  6.     getline(cin, NameP);
  7.     cout << "\t\t";
  8.     cin >> MarkP;
  9.     cin.ignore();
  10. }
  11.  
Also, you for loop is wrong. :
Expand|Select|Wrap|Line Numbers
  1. for (int x = 0; x < 15; x++)
  2. {
  3.     getInput(NameP[x], MarkP[x]);
  4.     displayResults(NameP, MarkP);
  5. }
  6.  
And initialize your string array with a string:
Expand|Select|Wrap|Line Numbers
  1. string NameP[15] = {""};
  2.  
Aug 23 '07 #7
how can i compare 2 string....
sample if i input a id number of a student and that number is already exist it must print that an id is already in use.
Aug 23 '07 #8
ilikepython
844 Expert 512MB
how can i compare 2 string....
sample if i input a id number of a student and that number is already exist it must print that an id is already in use.
Please don't ask questions in other people's threads. Use the "==" operator.
Aug 23 '07 #9
Ok for the getline, use this:
Expand|Select|Wrap|Line Numbers
  1. getline(cin, NameP);
  2.  
Also, you need a cin.ignore to eat the newline left by cin>>.
Expand|Select|Wrap|Line Numbers
  1. void getInput(string &NameP, int &MarkP)
  2. {
  3.     cout<<"Enter the Name of the student\n";
  4.     cout<<"Name\t\tMarks\n";
  5.  
  6.     getline(cin, NameP);
  7.     cout << "\t\t";
  8.     cin >> MarkP;
  9.     cin.ignore();
  10. }
  11.  
Also, you for loop is wrong. :
Expand|Select|Wrap|Line Numbers
  1. for (int x = 0; x < 15; x++)
  2. {
  3.     getInput(NameP[x], MarkP[x]);
  4.     displayResults(NameP, MarkP);
  5. }
  6.  
And initialize your string array with a string:
Expand|Select|Wrap|Line Numbers
  1. string NameP[15] = {""};
  2.  
thank you,i did that,now it is giving me two errors about getline.
this is the code that i did




#include<iostream>
#include<string>
using namespace std;
using std::getline;
void getInput(string & ,int&);
void displayResults(string [],int []);


int main()
{

int MarkP[15];

string NameP[15];

for(int x=1;x<15; x++)
{
getInput(NameP[x],MarkP[x]);
displayResults(NameP,MarkP);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{


cout<<"Enter the Name of the student\n";
cout<<"Name\t\tMarks\n";
getline(cin, NameP);
cout << "\t\t";
cin >> MarkP;
cin.ignore();

}
void displayResults(string &NameP,int &MarkP)
{
if(MarkP>=0&&MarkP>=39)
{
cout<<"\n failed";
}
Aug 23 '07 #10
gsi
51
Hi,
Firstly, your initialization of ' int MarkP[15]={0} ; ' initializes only the first element to zero, Same for the string array allocation.

Expand|Select|Wrap|Line Numbers
  1. for(int x=1;x<=15; x++)
  2. {
  3. getInput(NameP,MarkP);
  4. displayResults(NameP,MarkP);
  5. }
  6.  
Why do you have an array allocated if you are passing the same address to the the functions. You are always passing in the address of the first element by using Namep and MarkP. As stated previously your array is having an out of bound access.


Thanks,
gsi.
Aug 23 '07 #11
ilikepython
844 Expert 512MB
thank you,i did that,now it is giving me two errors about getline.
this is the code that i did




#include<iostream>
#include<string>
using namespace std;
using std::getline;
void getInput(string & ,int&);
void displayResults(string [],int []);


int main()
{

int MarkP[15];

string NameP[15];

for(int x=1;x<15; x++)
{
getInput(NameP[x],MarkP[x]);
displayResults(NameP,MarkP);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{


cout<<"Enter the Name of the student\n";
cout<<"Name\t\tMarks\n";
getline(cin, NameP);
cout << "\t\t";
cin >> MarkP;
cin.ignore();

}
void displayResults(string &NameP,int &MarkP)
{
if(MarkP>=0&&MarkP>=39)
{
cout<<"\n failed";
}
Is it? It compiles fine on Dev-Cpp 4.9.9.2. Also, your loop should start from 0, not 1.
Aug 23 '07 #12
Hi,
Firstly, your initialization of ' int MarkP[15]={0} ; ' initializes only the first element to zero, Same for the string array allocation.

Expand|Select|Wrap|Line Numbers
  1. for(int x=1;x<=15; x++)
  2. {
  3. getInput(NameP,MarkP);
  4. displayResults(NameP,MarkP);
  5. }
  6.  
Why do you have an array allocated if you are passing the same address to the the functions. You are always passing in the address of the first element by using Namep and MarkP. As stated previously your array is having an out of bound access.


Thanks,
gsi.
thanks for your help, but i'm new to this arrays so i'm putting all what i have.
mu proble now is if i compile the program it is complaining about getline.
Aug 23 '07 #13
gsi
51
Hi,
Sorry didnt lookup your previous post bfore submitting the reply. In the corrected version you are passing the same address to the display funtion while you are incrementing the address in the getinput function. in this case it must be displayResults(NameP[x],MarkP[x]);

Pls try this
Expand|Select|Wrap|Line Numbers
  1. for(int x=0;x<15; x++)
  2. {
  3. getInput(NameP[x],MarkP[x]);
  4. displayResults(NameP[x],MarkP[x]);
  5. }
  6.  
Also think of your usage of an array if you are not storing in any data.

Thanks,
gsi.
Aug 23 '07 #14
ilikepython
844 Expert 512MB
Firstly, your initialization of ' int MarkP[15]={0} ; ' initializes only the first element to zero, Same for the string array allocation.
That's only true for the string. The integer array is initialized with the value in the braces for all elements. Strings are automatically constructed with an empty string. There is no need to do this:
Expand|Select|Wrap|Line Numbers
  1. string arr[15] = {""};
  2.  
Sorry that was my mistake.
Aug 23 '07 #15
Hi,
Sorry didnt lookup your previous post bfore submitting the reply. In the corrected version you are passing the same address to the display funtion while you are incrementing the address in the getinput function. in this case it must be displayResults(NameP[x],MarkP[x]);


Also think of your usage of an array if you are not storing in any data.

Thanks,
gsi.
the way this program is; i have to input 15 students name and their marks and after that i have to display whether they have passed,supplementing or failed. that is why i'm storing those arrays before i can display them
Aug 23 '07 #16
ilikepython
844 Expert 512MB
Hi,
Sorry didnt lookup your previous post bfore submitting the reply. In the corrected version you are passing the same address to the display funtion while you are incrementing the address in the getinput function. in this case it must be displayResults(NameP[x],MarkP[x]);

Pls try this
Expand|Select|Wrap|Line Numbers
  1. for(int x=0;x<15; x++)
  2. {
  3. getInput(NameP[x],MarkP[x]);
  4. displayResults(NameP[x],MarkP[x]);
  5. }
  6.  
Also think of your usage of an array if you are not storing in any data.

Thanks,
gsi.
Yes, I noticed that but the OP's delcareation of the function takes an array, so I figured he wanted to print the values at every iteration. Not sure what you mean by incrementing the address in the input function.
Aug 23 '07 #17
ilikepython
844 Expert 512MB
the way this program is; i have to input 15 students name and their marks and after that i have to display whether they have passed,supplementing or failed. that is why i'm storing those arrays before i can display them
In you results function do you want to iterate over the array and display the results at the end or do you want to take a single student and call the function every iteration of the loop?
Aug 23 '07 #18
Yes, I noticed that but the OP's delcareation of the function takes an array, so I figured he wanted to print the values at every iteration. Not sure what you mean by incrementing the address in the input function.
this is the code that i have so far, actually i'm storing information before i can display it. i have to store 15 names and 15 marks of the students before i can display whether they have passed or failed





#include<iostream>
#include<string>
using namespace std;
using std::getline;
void getInput(string & ,int&);
void displayResults(string [],int []);


int main()
{

int MarkP[15];

string NameP[15];

for(int x=1;x<15; x++)
{
getInput(NameP[x],MarkP[x]);
displayResults(NameP,MarkP);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{


cout<<"Enter the Name of the student\n";
cout<<"Name\t\tMarks\n";
getline(cin,NameP);
cout << "\t\t";
cin >> MarkP;
cin.ignore();

}
void displayResults(string &NameP,int &MarkP)
{
if(MarkP>=0&&MarkP>=39)
{
cout<<"\n failed";
}




}
Aug 23 '07 #19
In you results function do you want to iterate over the array and display the results at the end or do you want to take a single student and call the function every iteration of the loop?
no sir, i have to store all the names and marks before i can display whether they have passed of failed.
Aug 23 '07 #20
gsi
51
Hi,
Sorry for the confusion it must have been 'iterating the array' rather than 'incrementing the address' . Also it would have been a problem only if he had intended to initialize the array with a value other than zero, since they are all intialized to zero if with less initializers than the declared array subscript. I shouldn't have pointed out that.

thanks,
gsi.
Aug 23 '07 #21
ilikepython
844 Expert 512MB
this is the code that i have so far, actually i'm storing information before i can display it. i have to store 15 names and 15 marks of the students before i can display whether they have passed or failed





#include<iostream>
#include<string>
using namespace std;
using std::getline;
void getInput(string & ,int&);
void displayResults(string [],int []);


int main()
{

int MarkP[15];

string NameP[15];

for(int x=1;x<15; x++)
{
getInput(NameP[x],MarkP[x]);
displayResults(NameP,MarkP);
}

return 0;
}
void getInput(string &NameP,int &MarkP)

{


cout<<"Enter the Name of the student\n";
cout<<"Name\t\tMarks\n";
getline(cin,NameP);
cout << "\t\t";
cin >> MarkP;
cin.ignore();

}
void displayResults(string &NameP,int &MarkP)
{
if(MarkP>=0&&MarkP>=39)
{
cout<<"\n failed";
}




}
Firstly, don't post the code again, if you didn't change anything, and if you did only post the relative parts. Second please use code tags when replying, they are on they right side of the page.

Ok, so what's the problem?:
Expand|Select|Wrap|Line Numbers
  1. for (int x = 0; x < 15; x++)
  2. {
  3.     getInput(NameP[x], MarkP[x]);
  4.     displayResults(NameP[x], MarkP[x]);
  5. }
  6.  
Aug 23 '07 #22
ilikepython
844 Expert 512MB
no sir, i have to store all the names and marks before i can display whether they have passed of failed.
Ok, then so you need to call the function after you are done storing the results:
Expand|Select|Wrap|Line Numbers
  1. for (int x = 0; x < 15; x++)
  2. {
  3.     getInput(NameP[x], MarkP[x]);
  4. }
  5. displayResults(NameP, MarkP);
  6.  
Then in displayResults:
Expand|Select|Wrap|Line Numbers
  1.     iterate over arrays:
  2.         determine results
  3.         display whatever
  4.  
Aug 23 '07 #23
gsi
51
Hi,

" i have to store all the names and marks before i can display whether they have passed of failed. "
Then do something like

Expand|Select|Wrap|Line Numbers
  1. for(i=0;i<15;++i)
  2. displayResults(NameP[x], MarkP[x]);
  3. }
  4.  
after removing the displayResults function from your previous loop.

Thanks,
gsi.
Aug 23 '07 #24
Firstly, don't post the code again, if you didn't change anything, and if you did only post the relative parts. Second please use code tags when replying, they are on they right side of the page.

Ok, so what's the problem?:
Expand|Select|Wrap|Line Numbers
  1. for (int x = 0; x < 15; x++)
  2. {
  3.     getInput(NameP[x], MarkP[x]);
  4.     displayResults(NameP[x], MarkP[x]);
  5. }
  6.  
i'm so sorry about that. okay the problem is that it is giving me this two errors that i don't know how to solve them.





Compiling...
(31) : error C2667: 'getline' : none of 2 overload have a best conversion
C:\Documents and Settings\200729335.LAB2-R7-C1\Desktop\assistance.cpp(31) : error C2668: 'getline' : ambiguous call to overloaded function
Error executing cl.exe.

assistance.exe - 2 error(s), 0 warning(s)
Aug 23 '07 #25
ilikepython
844 Expert 512MB
i'm so sorry about that. okay the problem is that it is giving me this two errors that i don't know how to solve them.





Compiling...
(31) : error C2667: 'getline' : none of 2 overload have a best conversion
C:\Documents and Settings\200729335.LAB2-R7-C1\Desktop\assistance.cpp(31) : error C2668: 'getline' : ambiguous call to overloaded function
Error executing cl.exe.

assistance.exe - 2 error(s), 0 warning(s)
That's wierd, it works on my compiler. I think the problem is something about the compiler having trouble with the overloaded function. Try this:
Expand|Select|Wrap|Line Numbers
  1. getline(cin, NameP, '\n');
  2.  
Edit:
What compiler are you using?
Aug 23 '07 #26
That's wierd, it works on my compiler. I think the problem is something about the compiler having trouble with the overloaded function. Try this:
Expand|Select|Wrap|Line Numbers
  1. getline(cin, NameP, '\n');
  2.  
Edit:
What compiler are you using?
i'm using microsoft visual c++ 6.0
Aug 23 '07 #27
gsi
51
Hi,
It works well with my compiler even, May be you should remove the redundant declararion ' using std::getline ', as you are pulling in the whole of std namespace in to your global scope by the previous line declaration of ' using namespace std ' in ur code.

Thanks,
gsi.
Aug 23 '07 #28
Hi,



Then do something like

Expand|Select|Wrap|Line Numbers
  1. for(i=0;i<15;++i)
  2. displayResults(NameP[x], MarkP[x]);
  3. }
  4.  
after removing the displayResults function from your previous loop.

Thanks,
gsi.
i have already done that, but the problem is. the compiler cannot convert parameter 1
Aug 23 '07 #29
ilikepython
844 Expert 512MB
i have already done that, but the problem is. the compiler cannot convert parameter 1
You have to change your function to:
Expand|Select|Wrap|Line Numbers
  1. void displayResults(string NameP, int MarkP);
  2.  
Aug 23 '07 #30
[quote=ilikepython]You have to change your function to:
Expand|Select|Wrap|Line Numbers
  1. void displayResults(string NameP, int MarkP);
  2.  
[/QUOT


which means i have to change the the other function
void getInput to (string NameP[],int MarkP[])
Aug 23 '07 #31
[quote=Nkhosinathie]
You have to change your function to:
Expand|Select|Wrap|Line Numbers
  1. void displayResults(string NameP, int MarkP);
  2.  
[/QUOT


which means i have to change the the other function
void getInput to (string NameP[],int MarkP[])
this is the most c++ program i have ever struggled to compile,i haven't even eaten i've been struggling all day with it.
Aug 23 '07 #32
ilikepython
844 Expert 512MB
[quote=Nkhosinathie]
You have to change your function to:
Expand|Select|Wrap|Line Numbers
  1. void displayResults(string NameP, int MarkP);
  2.  
[/QUOT


which means i have to change the the other function
void getInput to (string NameP[],int MarkP[])
No, no, no. Your other function is fine. You use it in a loop. Like this:
Expand|Select|Wrap|Line Numbers
  1. for (int x = 0; x < 15; x++)
  2. {
  3.     getInput(NameP[x], Mark[x]);
  4. }
  5. for (int x = 0; x < 15; x++)
  6. {
  7.     displayResults(NameP[x], Mark[x]);
  8. }
  9.  
Then you functions will look like this:
Expand|Select|Wrap|Line Numbers
  1. void getInput(string &NameP, int &MarkP);
  2. void displayResults(string NameP, int MarkP);
  3.  
Aug 23 '07 #33
ilikepython
844 Expert 512MB
[quote=Nkhosinathie]

this is the most c++ program i have ever struggled to compile,i haven't even eaten i've been struggling all day with it.
Don't worry, you'll get it. Please eat though, not good to compile on an empty stomach ;).
Aug 23 '07 #34
[quote=ilikepython]
Don't worry, you'll get it. Please eat though, not good to compile on an empty stomach ;).

i won't sleep before i get it. sir i'm sorry if i'm stressing u but again this are the errors i'm getting after compiling,i'm really sorry if i'm stressing u




Compiling...
i
(37) : error C2667: 'getline' : none of 2 overload have a best conversion
C:\Documents and Settings\200729335.LAB2-R7-C1\Desktop\i'm serious.cpp(37) : error C2668: 'getline' : ambiguous call to overloaded function
Error executing cl.exe.

i.exe - 2 error(s), 0 warning(s)
Aug 23 '07 #35
[quote=Nkhosinathie]


i won't sleep before i get it. sir i'm sorry if i'm stressing u but again this are the errors i'm getting after compiling,i'm really sorry if i'm stressing u




Compiling...
i
(37) : error C2667: 'getline' : none of 2 overload have a best conversion
C:\Documents and Settings\200729335.LAB2-R7-C1\Desktop\i'm serious.cpp(37) : error C2668: 'getline' : ambiguous call to overloaded function
Error executing cl.exe.

i.exe - 2 error(s), 0 warning(s)
Aug 23 '07 #36
[quote=Nkhosinathie]sir.let me give that statement with the error:'
it is this one, the get line below





cout<<"Enter the Name of the student\n";
cout<<"Name\t\tMarks\n";
getline(cin,NameP);

cout << "\t\t";
cin>>MarkP;
cin.ignore()
Aug 23 '07 #37
ilikepython
844 Expert 512MB
[quote=Nkhosinathie]
sir.let me give that statement with the error:'
it is this one, the get line below





cout<<"Enter the Name of the student\n";
cout<<"Name\t\tMarks\n";
getline(cin,NameP);

cout << "\t\t";
cin>>MarkP;
cin.ignore()
Ok, try this:
Expand|Select|Wrap|Line Numbers
  1. cout<<"Enter the Name of the student\n";
  2. cout<<"Name\t\tMarks\n";
  3. char cstr[256];
  4. cin.getline(cstr, 256);
  5. NameP += cstr;
  6.  
Hope it works.
Aug 23 '07 #38
gsi
51
Hi,

I am pretty sure that the above code snippet works with ur compiler, The global getline function defined in std namespace is not working as expected in vc++ 6. Also with strings it has a bug it seems, check out this,

http://support.microsoft.com/kb/240015

Thanks,
gsi.
Aug 23 '07 #39
[quote=ilikepython]
Ok, try this:
Expand|Select|Wrap|Line Numbers
  1. cout<<"Enter the Name of the student\n";
  2. cout<<"Name\t\tMarks\n";
  3. char cstr[256];
  4. cin.getline(cstr, 256);
  5. NameP += cstr;
  6.  
Hope it works.

thanks for the help,i will compile it and then i'll come back to you to tell you the results.i really appreciate your help
Aug 24 '07 #40
[quote=Nkhosinathie]


thanks for the help,i will compile it and then i'll come back to you to tell you the results.i really appreciate your help

sir the first function to input the marks and names is working fine thanks to you.
this is the code:

void getInput(string& name,int& number)
{

cout<<"enter the marks of the student\n";
cin>>number;
cin.get();
cout<<"enter your first and last names\n";
getline(cin,name,'\n');
}

now i'm having the problem for the second function to display the results.
this is the code: i don't know how to retrieve the information from the input function.

displayResults(string names[],int marks[])
{

for(int h=0;h<3;h++)
Aug 24 '07 #41
[quote=Nkhosinathie]


sir the first function to input the marks and names is working fine thanks to you.
this is the code:

void getInput(string& name,int& number)
{

cout<<"enter the marks of the student\n";
cin>>number;
cin.get();
cout<<"enter your first and last names\n";
getline(cin,name,'\n');
}

now i'm having the problem for the second function to display the results.
this is the code: i don't know how to retrieve the information from the input function.

displayResults(string names[],int marks[])
{

for(int h=0;h<3;h++)
actually my question is how to retrieve a data in an array?
Aug 24 '07 #42
ilikepython
844 Expert 512MB
[quote=Nkhosinathie]

actually my question is how to retrieve a data in an array?
You loop over it with a for loop:
Expand|Select|Wrap|Line Numbers
  1. void displayResults(string names[], int marks[])
  2. {
  3.     for (int i = 0; i < 15; i++)
  4.     {
  5.         // names[i] or marks[i] is the current element
  6.     }
  7. }
  8.  
Aug 24 '07 #43
[quote=ilikepython]
You loop over it with a for loop:
Expand|Select|Wrap|Line Numbers
  1. void displayResults(string names[], int marks[])
  2. {
  3.     for (int i = 0; i < 15; i++)
  4.     {
  5.         // names[i] or marks[i] is the current element
  6.     }
  7. }
  8.  
thank you so much guys,i really appreciate your help and i managed to finish the program today afternoon.thank you so much and i'll continue helping others,thank you
Aug 24 '07 #44
[quote=Nkhosinathie]

thank you so much guys,i really appreciate your help and i managed to finish the program today afternoon.thank you so much and i'll continue helping others,thank you

can someone pls close the thread.thanks.
Aug 26 '07 #45
JosAH
11,448 Expert 8TB
[quote=Nkhosinathie]


can someone pls close the thread.thanks.
Consider it done.

kind regards,

Jos
Aug 26 '07 #46

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
5
by: Robert | last post by:
Hi, Is there some way of using an array of strings? Like in basic? I know you have to create an array of chars so i think it has to be an 2d array or something... Really stuck here... Thanks...
10
by: Ian Todd | last post by:
Hi, I am trying to read in a list of data from a file. Each line has a string in its first column. This is what i want to read. I could start by saying char to read in 1000 lines to the array( i...
2
by: Steve | last post by:
I want an initializer for an array of pointers to arrays of strings. So I can do something like this: const char *t1 = { "a", "b", "c", NULL }; const char *t2 = { "p", "q", NULL }; const char...
1
by: Jeff | last post by:
I am struggling with the following How do I marshal/access a pointer to an array of strings within a structure Than Jef ----------------------------------------------------------------
7
by: Bob Rock | last post by:
Hello, converting from the managed to the unmanaged world (and viceversa strings) and byte arrays is something I do often and I'd like to identify the most correct and efficient way to do it....
6
by: Broeisi | last post by:
Hello, I wrote the tiny progam below just to understand arrays and strings better. I have 2 questions about arrays and strings in C. 1. Why is it that when you want to assign a string to an...
23
by: arnuld | last post by:
i was doing exercise 4.3.1 - 4.29 of "C++ Primer 4/e" where authors, with "run-time shown", claim that C++ Library strings are faster than C-style character strings. i wrote the same programme in...
19
by: bowlderyu | last post by:
Hello, all. If a struct contains a character strings, there are two methods to define the struct, one by character array, another by character pointer. E.g, //Program for struct includeing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.