vegyta's Profile User Rating: -----

Reputation: 1 Apprentice
New Members
Active Posts:
13 (0.02 per day)
08-April 12
Profile Views:
Last Active:
User is offline Feb 18 2013 03:44 PM

Previous Fields

Who Cares
OS Preference:
Favorite Browser:
Favorite Processor:
Favorite Gaming Platform:
Your Car:
Who Cares
Dream Kudos:
Icon   vegyta has not set their status

Posts I've Made

  1. In Topic: How to add a dashed (----) Line Every 10 Lines

    Posted 12 Dec 2012

    How do you organize your info in payroll.dat?I'm assuming that a single line in payroll.dat has info for 1 person.Again,i think you only need to declare count as an integer(because % works only with integers) and don't use another variable for the same purpose(the line variable).
    Here,i think it may be another problem.You assume
    DATACOUNT = 50
    that you have only 50 lines of data in your file.I don't know how to handle files with C/C++ programs,so assuming that
    infile >> name >> hours >> rate;  //read data 
    read's only 1 line of data,you must have a way to move from the current line to the next line.
    only increments count,but in your file you are still on the current line.Hope this helps
  2. In Topic: How to add a dashed (----) Line Every 10 Lines

    Posted 12 Dec 2012

    Why didn't you put the complete code?It is much better to have all the code you are compiling instead of a sample.I'm assuming that count and is the current line you are writing your info,so you may declare count as an integer and get rid of the error.I think it would be better not to use the line variable(because you only use it once at line 18),leave only count.Again post the entire code you are using.
  3. In Topic: Return to main menu after invalid choice

    Posted 4 Aug 2012

    What compiler are you using?I used Codelite with MinGW and got 1 warning,but is worked fine.
  4. In Topic: Return to main menu after invalid choice

    Posted 4 Aug 2012

    From what I understood the context is the folowing: you have a program who must process data related to travels,more exactly the program must be able to create a sales receip,customer contact card,trip mileage report,and Balance a checkbook. You want your program to have a menu with each of these options,and when you select one option or another the program will do something diffrent.Also,after selecting the first option you want the chioce of running again this option or not(if not,I assumed that you wanted the user to return to the main menu),and if the user didn't press Y or N, you want it to return to the main menu.

    Based on your second post(#3),the problem was that the user inputs a new selection,but that had no effect because the program exited.
    Here is what happenes in your program:
    Step 1: the program gets a selection from the user
    Step 2: the program enters the switch statement and searches for the number of the selection,if it's not defined it executes the default branch.Let's say that the user input's 1(selects the first statement).
    Step3 : select is 1,so the program runs the instructions on the branch where the option 1 is defined(case 1): it enters the do while loop
    Step 4: in the do while loop it displays a message(Would you like to run the receipt program again? (Y/N) :),and ask the user to imput a value for the another variable.Let' say the user inputs the caracter 'A'
    Step 5: Since the caracter 'A' is Not 'Y' or 'N' it executes the instuctions in the If branch
    Step 6:In the If branch the value returned by getSelection is being assigned to selection
    Step 7: After the assignment,if escapes out of the do while block(because another is 'A' and not 'Y'),it executes the break instruction,and break's out of the switch block,ending the program

    The problem is that,after the value of the selection is modified,you must return at the beginning of the switch block,and reevaluate the whole switch block instruction with the new value of selection.That is your problem,you are not returning back into the switch block,to reevaluate it with the new value.

    So,to solve the problem you must put your switch block into a loop.My code for your problem is the following:

    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <fstream>
    using namespace std;
    //function prototypes
    int getSelection();
    void displayThankYou();
    int RunReceipAgain()
    	char answer;
    	cout << "Would you like to run the receipt program again? (Y/N) : ";
        cin >> answer;
    		return -1;  
       else	if(answer=='Y')
                return 1;	
       return -1;	
    int RunProgramAgain()
    	char answer;
    	cout << "Would you like to run the program again? (Y/N) : ";
        cin >> answer;
    		return 0;
       else	if(answer=='Y')
                return -1;	
      cout<<"I do not recognize the command,you must type Y for Yes or N for No\n";	
    int main()
    {//Begin main function
    	//declare variables
    	int selection=-1;
    if(selection!=1) //remove this If,for program to run again for all options
        selection = getSelection();
    	switch (selection)
    	     case 0: //nothing to do,just wait to exit the program
    		case 1: /*Code for creating a sales receipt*/ 
    				 //Run the Receip Again ?
    		cout << "***************************************" << endl;
    		cout << "***************************************" << endl;
    		cout << "******   T H A T  W A S  N O T   ******" << endl;
    		cout << "****** A  V A L I D  O P T I O N ******" << endl;
    		cout << "***************************************" << endl;
    		cout << "***************************************" << endl << endl;
    	    selection= RunProgramAgain();
    	} //end switch
    return 0;
    //end of main function
    //*******************function definitions
    int getSelection()
    	int choice;
    	cout << "Option          Description" << endl;
    	cout << "---------------------------" << endl;
    	cout << "   1            Create a sales receipt"<< endl;
    	cout << "   2            Create a customer contact card" << endl;
    	cout << "   3            Balance a checkbook"<< endl;
    	cout << "   4            Create a trip mileage report"<< endl;
    	cout << "   0            Exit program" << endl << endl;
    	cout << "What is your selection?";
    	cin >> choice;
    	return choice;
    void displayThankYou()
    	cout << "**************************************" << endl;
    	cout << "**************************************" << endl;
    	cout << "*******    T H A N K  Y O U    *******" << endl;
    	cout << "*******    F O R  U S I N G    *******" << endl;
    	cout << "******* T H I S  P R O G R A M *******" << endl;
    	cout << "**************************************" << endl;
    	cout << "**************************************" << endl;

    First of all,i did not use the 2 char variables another and answer,instead i created 2 new functions: RunReceipAgain() and RunProgramAgain().Both functions return an int value.These functions ask the user if he wants to run the receip/program again and retuns a value based on the user's answer.In the main() function i assumed that the options are pozitive numbers,and the value 0 ends the program.
    The while block will keep looping as long as selection isn't 0(exit the program).In the switch block for 0,the program ends,for option 1,after the code for the receip generation is run selection is given the result returned from the RunReceipAgain() function.If it;s 1,then on the second iteration of the while loop the switch statement will execute the first option,if it's -1 then the user will return to the menu(i assumed that if the user press N as the answer to the question "Would you like to run the receipt program again? (Y/N),you would want to go back to the menu) the the program returnes to the main menu(if you want to end the program,instead of -1,put 0).

    In the default section,the variable selection is given the value returned by RunProgramAgain() witch returnes 0 if you don;t want to run it again,or -1 if you do.

    On the other option(2,3,4,etc),if you want the user to be asked if he want's to run the program again or not just put the line
    selection= RunProgramAgain();

    before the break instruction of the branch.

My Information

Member Title:
New D.I.C Head
23 years old
October 18, 1990
Years Programming:
Programming Languages:
C/C++ Java,Mysql,PHP,HTML,CSS

Contact Information

Click here to e-mail me
Yahoo  vegyta2004



vegyta has no profile comments yet. Why not say hello?