Thread: just practice

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    21

    just practice

    I dont understand why the 2 errors.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    char choice;
    void M();
    void C();
    void Process();
    
    void M(){
    	cout <<"Multiplication\n";
    }
    void C(){
    	cout << "Calculation\n";
    }
    void Process(){
    	cout << "Make a choice\n"
    		<< "C or M only\n";
    	cin >> choice;
    	while (strcmp(choice, "M")!=0) || (strcmp(choice, "C")!=0){
    		cout << "ERROR Enter again";
    	cin >> choice;
    	
    	}
    	return;
    }
    
    
    void main () {
    	Process();
    	while (strcmp(choice, "M") == 0){
    		M();
    	}
    	return;
    	while (strcmp(choice, "C") == 0){
    		C();
    		return ;
    	}
    	
    }
    Any idea?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What errors?

    Apart from main returning void, and the excess of return statements which result in unreachable code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    21
    When I run it, it returns two errors and I dont understand the debug.
    Could you be a bit more specific? thanks

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    One thing is your variable choice is a char and you are using strcmp for comparison. You would do better to compare using this way:
    Code:
    while ( choice != 'M' && choice != 'C' ){
    Make the changes in the other two places as well.

    [edit]Also, if you do intend to use any of the C-style string routines I suspect you meant #include <cstring> and not #include <string>[/edit]
    Last edited by hk_mp5kpdw; 05-27-2004 at 07:11 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    21
    Oh, I get it... I can only use strcmp with strings, right?

    It works now, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Practice Projects
    By LordBronz in forum C++ Programming
    Replies: 11
    Last Post: 05-30-2011, 11:06 PM
  2. Need to practice more while learning
    By KidMan in forum C Programming
    Replies: 1
    Last Post: 10-24-2007, 02:48 PM
  3. Need Practice exercises
    By blindman858 in forum C++ Programming
    Replies: 4
    Last Post: 06-18-2005, 01:30 AM
  4. Best practice: string manipulation functions
    By samadhi in forum C Programming
    Replies: 4
    Last Post: 09-23-2004, 05:16 PM
  5. Practice
    By Octorok101 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2002, 03:14 PM