Thread: C++ confusion

  1. #1
    charlie
    Guest

    Unhappy C++ confusion

    iam designing a menu driven program and want to call a function
    when chosen a selection. My function contains two parameters
    of type char array and of type int array. Could any1 help me here...?should i call it in main or can i call it in a switch statement or either....?. I have another question also
    i have a parrallel array one of each type char and int
    and want the user to input a specific character e.g a roman numeral and have the equivalent value in the int array.My menu driven fragment of code is a do while loop.....also with the parrallel arrays i want to be able to add the values of array type int, should i creat another array and use assigning techniques or
    shouldnt i use another array at all?. If you are able to help me , could you please give me an example... to give me an idea of what your talking about... would be much appreciated.#iclude < iostream.h>

    #include <stdlib.h>
    #include <string.h >
    #include <iomanip.h>

    const int MAXCHARS = 16;
    const int MAXVALS = 81;
    void menu (char);
    void assign3 ( int [], int []) ;

    int main ()
    {
    char roman[MAXCHARS];
    int tot_value [MAXVALS];
    int array3[MAXVALS];
    char choice; menu (choice);
    // function call void assign (int, int );
    return 0;
    }
    void menu (char choice)
    {
    do
    {
    // This is the menu displayed to the screen
    cout <<setw(10) << " The KMA Menu " << endl;
    cout <<setw(10)<< "============================"<<endl;
    cout << "1. Help\n";
    cout << "2. Convert to Arabic\n";
    cout << "3. Exit\n";
    // This read the user selection
    cout << " Enter your choice : ";
    cin choice ;
    // This selection acts on the user selection.
    switch (choice)
    { case '1' : cout <<< " Back to Instruction screen\n";
    break;
    case '2' : cout <<< " Function process. Convert to arabic\n";
    void assign ( int , int ) ; // want to call this function but cant?
    break;
    case '3' : exit (0);
    default : cout <<setw(12) <<" Invalid number. Enter numbers between 1-3"; break;
    }
    } while (1);
    }
    void assign (int roman [], int array3 [])
    {
    int i;
    for (i=0; i< MAXCHARS ; i ++ )
    cout <<" Enter a roman numeral:";
    cin>> roman[i] ;
    int j;
    for ( j=0 ; j<MAXVALS;j++ )
    switch (i)
    {
    case 'M' : array3[j] = 1000;
    case 'D' : array3 [j] = 500;
    case 'C' : array3 [j] = 100;
    case 'L' : array3 [j] = 50;
    case 'X' : array3 [j] = 10;
    case 'V' : array3 [j] = 5;
    case 'I' : array3 [j] = 1;
    default : cout << " Invalid roman numeral. Please re-enter Roman numeral.\n";
    break;
    return (i);
    }
    }
    }

    sorri bout the indentation......

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Thumbs up completely fixed

    I have completely fixed your code

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h > 
    #include <iomanip.h> 
    
    const int MAXCHARS = 16; 
    const int MAXVALS = 81; 
    void menu (char); 
    void assign3 ( int [], int []) ; 
    
    int main () 
    { 
    char roman[MAXCHARS]; 
    int tot_value [MAXVALS]; 
    int array3[MAXVALS]; 
    char choice; menu (choice); 
    // function call void assign (int, int ); 
    return 0; 
    } 
    void menu (char choice) 
    { 
    do 
    { 
    // This is the menu displayed to the screen 
    cout <<setw(10) << " The KMA Menu " << endl; 
    cout <<setw(10)<< "============================"<<endl; 
    cout << "1. Help\n"; 
    cout << "2. Convert to Arabic\n"; 
    cout << "3. Exit\n"; 
    // This read the user selection 
    cout << " Enter your choice : "; 
    cin >> choice ;
    // This selection acts on the user selection. 
    switch (choice) 
    { case '1' : cout << " Back to Instruction screen\n";
    break; 
    case '2' : cout << " Function process. Convert to arabic\n";
    void assign ( int , int ) ; // want to call this function but cant? 
    break; 
    case '3' : exit (0); 
    default : cout <<setw(12) <<" Invalid number. Enter numbers between 1-3"; break; 
    } 
    } while (1); 
    } 
    int assign (int roman [], int array3 [])
    { 
    int i; 
    for (i=0; i< MAXCHARS ; i ++ ) 
    cout <<" Enter a roman numeral:"; 
    cin>> roman[i] ; 
    int j; 
    for ( j=0 ; j<MAXVALS;j++ ) 
    switch (i) 
    { 
    case 'M' : array3[j] = 1000; 
    case 'D' : array3 [j] = 500; 
    case 'C' : array3 [j] = 100; 
    case 'L' : array3 [j] = 50; 
    case 'X' : array3 [j] = 10; 
    case 'V' : array3 [j] = 5; 
    case 'I' : array3 [j] = 1; 
    default : cout << " Invalid roman numeral. Please re-enter Roman numeral.\n"; 
    break; 
    return (i); 
    } 
    }

  3. #3
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    oh crap. I still need to fix it a bit...sorry

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    oops

    oops. No I don't. I thought the code u posted was meant to actually do what it says it does...but its just the menu...

  5. #5
    Unregistered
    Guest

    Re: oops

    Originally posted by face_master
    oops. No I don't. I thought the code u posted was meant to actually do what it says it does...but its just the menu...
    Wut do you mean by " its just the menu "?
    I also appreciate the time u spent working on my error.

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    why are you passing a char to menu() ?

    Its ridiculous.... just make choice local to menu....
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terrible confusion with time variables
    By LowlyIntern in forum C++ Programming
    Replies: 12
    Last Post: 08-01-2008, 07:23 AM
  2. C++ Classes: Use, Misuse...Confusion.
    By Snorpy_Py in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2006, 01:46 AM
  3. for loop confusion
    By Enges in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2006, 08:21 AM
  4. Server-net newbie confusion
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 04-28-2005, 02:08 AM
  5. confusion with increment and decrement operators
    By cBegginer in forum C Programming
    Replies: 6
    Last Post: 03-19-2005, 03:45 PM