functions using strings and arrays

Reply

Join Date: Aug 2007
Posts: 1
Reputation: sandile77 is an unknown quantity at this point 
Solved Threads: 0
sandile77 sandile77 is offline Offline
Newbie Poster

functions using strings and arrays

 
0
  #1
Aug 22nd, 2007
i'm writing a program to capture marks and names of 15 students and then i'll be using a function to display whether those students have failed,supplement or passed. but the problem is i'm using strings to capture those names and i'm using arrays to capture those names and the marks.i'm really confused right now. i've tried everything i can think of. this is what i did below and any suggestions are welcome



  1. #include<iostream>
  2.  
  3. using namespace std;
  4. #include<iomanip>
  5.  
  6. void getInput(char[] ,int&);
  7. void displayResults(char[],int&);
  8.  
  9. int main()
  10. {
  11. int x;
  12.  
  13. int MarkP ;
  14.  
  15. char NameP[15];
  16.  
  17. for(x=1;x<=15; x++)
  18. {
  19. getInput(NameP,MarkP);
  20. displayResults(NameP,MarkP);
  21. }
  22.  
  23. return 0;
  24. }
  25. void getInput(char NameP[],int &MarkP)
  26.  
  27. {
  28. cout<<"Name\t\tMarks\n";
  29. cout<<"Enter the Name of the student\n";
  30. cin>>NameP;
  31. cout<<"\t\t";
  32. cin>>MarkP;
  33.  
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. void displayResults(char NameP[],int &MarkP)
  43. {
  44. if(MarkP<=39)
  45.  
  46. cout<<"you failed the course and come next year to repeat\n";
  47.  
  48. if(MarkP>=40 && MarkP<=49)
  49.  
  50. cout<<"You may write the supplementary examination\n";
  51.  
  52. if(MarkP>=50 && MarkP<=74)
  53.  
  54. cout<<"Congratulations!!You passed the examination\n";
  55.  
  56. if(MarkP>=75 && MarkP<=100)
  57.  
  58. cout<<"You passes with a distinction\n";
  59.  
  60.  
  61. }
Last edited by stymiee; Aug 22nd, 2007 at 4:04 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 376
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: functions using strings and arrays

 
0
  #2
Aug 22nd, 2007
What exactly are you stuck on?
Are you allowed to std::strings instead of c-style char arrays?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,671
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

Re: functions using strings and arrays

 
0
  #3
Aug 22nd, 2007
1) Welcome to DaniWeb! Please use code tags for future posts with code or indentation you wish to preserve.

2) Please describe what problem you are experiencing. Does the code you post not compile? Does it compile but not run? Does it run but give erroneous output? Do you get error messages or warnings (If so please copy and paste the first couple messages into the post.)? Do you not understand a concept involving C++ or the underlying algorithm?

Quickly scanning your posted code I don't see a glaring error, but I'm not sure what your problem is for sure. I suspect you may be suffering from the magic number blues, but I can't be sure.

3) A string is, at minimum, a null terminted char array. That means if you have a char array without a null char then you don't have a string. Some strings, like STL strings or APStrings or TStrings or CStrings have other very useful features besides just the null termination but they all have, or are, null terminated char arrays. The type of string you use in your post is the bare C style string, otherwise known as a simple null terminated char array.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC