School assignment...NEED HELP

This is a discussion on School assignment...NEED HELP within the C++ Programming forums, part of the General Programming Boards category; OKay here's the program Im suppose to write.. it involves looping and branching(I think ) ****************************************** Code: #include <iostream> int ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    13

    School assignment...NEED HELP

    OKay here's the program Im suppose to write.. it involves looping and branching(I think )
    ******************************************
    Code:
    #include <iostream>
    
    
    
    int main()
    {
     
       using namespace std;
    string fullname,Student_No,Phone;
    
    
    int option;
    
    	char Sex;
    	int Age;	
       
        cout << "1)... Add Student Information" << endl;
        cout << "2)... View Last Students Information" << endl;
        cout << "3)... Quit" << endl;
        cin >> option;
        
        if (option == 1)
        {      
    	cout << "Name:" << endl;
    	cin >>fullname;
    	cout << "Sex" << endl;
    	cin >>Sex;
    	cout << "Please enter age of Student:" << endl;
    	cin >>Age;
    	cout << "Please enter the Student's Number:" << endl;
    	cin >>Student_No;
    	cout << "Please enter the Students phone number"<< endl;
    	cin >>Phone;
    	}
    	
    	if (option == 2)
    	{}
    	
    	return 0;
    }
    ************************************

    WHat I need help with is:
    You see option 2.. what do I type in, in order to view the last student info

    AND

    when entering option 3..how do I quit the program.... I am sorry If my english isnt the best..


    MANY MANY thanks in advance to anyone that can help me

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    First you need to add #include <string>, which leads me to believe you haven't tried anything.
    Anyways...
    when entering option 3..how do I quit the program
    As your program is now, you needn't do anything. You could just throw in a return 0 though

    You see option 2.. what do I type in, in order to view the last student info
    In context of the program, this question doesn't make any sense. All of the student information is going to be null.

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    You should make a loop that keeps going until the user wants to quit like this:

    Code:
    while(option!=3) {
    // put code here
    
    }

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    13
    Quote Originally Posted by MadCow257
    First you need to add #include <string>, which leads me to believe you haven't tried anything.
    Anyways...

    As your program is now, you needn't do anything. You could just throw in a return 0 though


    In context of the program, this question doesn't make any sense. All of the student information is going to be null.
    THANK YOU VERY VERY MUCH you guys for replying

    Sorry, my english is bad..

    Code:
    cout << "1)... Add Student Information" << endl;
        cout << "2)... View Last Students Information" << endl;
        cout << "3)... Quit" << endl; 
        cin >> option;
    I copy what is wrote on the handout

    'When option 1 is selected the user must then be prompted to enter requried information. When option 2 is selected the Lat Student Information should be displayed to the user. When option 3 is selected the program should exit.


    Make sure the program handles the following problems

    a. Invalid Menu Choice
    b. No Student Information
    c. Wrong entry of information (sex must only be M or F)
    d. Students number cant be ZERO"

    ^ WHat do they mean?? .. and how do I work them



    BTW: The 'code' which I entered in 1st post.. Is it right so far??.. because when I play the program and select option 1.. I get this;

    Name
    John Macy
    Age
    Sex
    Phone

    I cant enter anything for the last 3 options.. I think its because I put a space in the name.. but how do I resolve this


    I understand that there is alot to answer here.. but I wold be so GREATFUL because this assignment I have to hand up is 30% of my computing class.


    Thank you again

  5. #5
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Initliaize option to NULL

    Add this over the input/output section of the program
    while (option != 3)

    c. Wrong entry of information (sex must only be M or F)
    while (sex != 'M' && sex != 'F')

    the other validation portions can be approached similary

    Now, it would be smart to group all of the student info variables into a struct, and then make a vector of those structs. To display the last students info, you can use vector.end() to get an iterirator to the last student. Then just cout all of the members...

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    well what i do for remembering names is i use a underscore and make it say "plese use a underscore instead of a space" and sutch

    try that

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    13
    Quote Originally Posted by MadCow257
    Initliaize option to NULL

    Add this over the input/output section of the program
    while (option != 3)


    while (sex != 'M' && sex != 'F')

    the other validation portions can be approached similary

    Now, it would be smart to group all of the student info variables into a struct, and then make a vector of those structs. To display the last students info, you can use vector.end() to get an iterirator to the last student. Then just cout all of the members...
    Sorry I am really new to ALL of this.. How to I initliaize option to null ( which option?).. I really dont understand what you are saying because I am new to english too..sorry

    Plus its only the very basic stuff we are doing with c++

  8. #8
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    How to I initliaize option to null ( which option?)
    ...the option, int option

    Code:
    int option = NULL;

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    13
    Quote Originally Posted by MadCow257
    ...the option, int option

    Code:
    int option = NULL;
    Thanks.. so that would be for option 3 then?

    I am so slow at this stuff

  10. #10
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    This is the basis
    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
    	using namespace std;
    	string fullname,Student_No,Phone;
    
    	int option = NULL;
    
    	char Sex;
    	int Age;	
    
    	while (option != 3)
    	{
    		cout << "1)... Add Student Information" << endl;
    		cout << "2)... View Last Students Information" << endl;
    		cout << "3)... Quit" << endl;
    		cin >> option;
    
    		if (option == 1)
    		{      
    			cout << "Name:" << endl;
    			cin >>fullname;
    			cout << "Sex" << endl;
    			cin >>Sex;
    			cout << "Please enter age of Student:" << endl;
    			cin >>Age;
    			cout << "Please enter the Student's Number:" << endl;
    			cin >>Student_No;
    			cout << "Please enter the Students phone number"<< endl;
    			cin >>Phone;
    		}
    	
    		if (option == 2)
    		{}
    	}
    	return 0;
    }
    Now you need to add in

    Code to validate each of the inputs that you recieve, and
    Code to display the last student's info

    I must also recommend that you read some of the tutorials,
    http://www.cprogramming.com/tutorial.html
    especially the one on loops

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    13
    Quote Originally Posted by MadCow257
    Now you need to add in

    Code to validate each of the inputs that you recieve, and
    Code to display the last student's info

    I must also recommend that you read some of the tutorials,
    http://www.cprogramming.com/tutorial.html
    especially the one on loops
    THank you.. LOL.. I better read up on it quickly ..TTHanks again

  12. #12
    Registered User
    Join Date
    Mar 2006
    Posts
    13
    Will the tutorial show me how to complete option 2??.. (displaying last student info).. Is that also under the heading looping?

  13. #13
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Code:
    int option = NULL;
    This may be easier to understand: to put it simply, when you declare a variable like this:

    int option;

    set it equal to 0:

    int option = 0;

    You can safely ignore the following:
    Now, it would be smart to group all of the student info variables into a struct, and then make a vector of those structs. To display the last students info, you can use vector.end() to get an iterirator to the last student.
    because based on what you've posted so far, that advice is way beyond your C++ skill level at this point in your studies.

    Will the tutorial show me how to complete option 2??
    Probably not, but it may give you some ideas.

    You are essentially asking for the members of this forum to cheat for you on 30% of your grade. If you have some specific questions about C++ syntax or why some part of your code isn't working, then post them, and people will be glad to answer them. Otherwise, you have to figure it out how to do the program on your own. If it's not your work, then you don't deserve the grade.
    Last edited by 7stud; 03-09-2006 at 02:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for school assignment
    By Allynia in forum C Programming
    Replies: 9
    Last Post: 04-29-2008, 04:07 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Replies: 1
    Last Post: 10-27-2006, 02:21 PM
  4. stupid school assignment
    By major_small in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 11-20-2003, 10:06 AM
  5. School Shooting in Germany
    By Golden Bunny in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 04-27-2002, 02:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21