944,183 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1092
  • C++ RSS
Aug 22nd, 2007
0

functions using strings and arrays

Expand Post »
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



c++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sandile77 is offline Offline
1 posts
since Aug 2007
Aug 22nd, 2007
0

Re: functions using strings and arrays

What exactly are you stuck on?
Are you allowed to std::strings instead of c-style char arrays?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 22nd, 2007
0

Re: functions using strings and arrays

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: T9 Predictive input and dictionary
Next Thread in C++ Forum Timeline: cam ActiveX control?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC