| | |
functions using strings and arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 1
Reputation:
Solved Threads: 0
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)
#include<iostream> using namespace std; #include<iomanip> void getInput(char[] ,int&); void displayResults(char[],int&); int main() { int x; int MarkP ; char NameP[15]; for(x=1;x<=15; x++) { getInput(NameP,MarkP); displayResults(NameP,MarkP); } return 0; } void getInput(char NameP[],int &MarkP) { cout<<"Name\t\tMarks\n"; cout<<"Enter the Name of the student\n"; cin>>NameP; cout<<"\t\t"; cin>>MarkP; } void displayResults(char 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"; }
Last edited by stymiee; Aug 22nd, 2007 at 4:04 pm. Reason: added code tags
•
•
Join Date: Jul 2005
Posts: 1,673
Reputation:
Solved Threads: 261
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.
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.
![]() |
Similar Threads
- arrays and strings (Java)
- strings in c (C++)
- assigning arrays in VB (Visual Basic 4 / 5 / 6)
- C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays (C++)
- Adding decimal numbers together? (C)
- Create Function that prints letters, words and sentences (C++)
- Searching in documents... (C++)
Other Threads in the C++ Forum
- Previous Thread: T9 Predictive input and dictionary
- Next Thread: cam ActiveX control?
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






