Thread: struct, arrays, srand...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    struct, arrays, srand...

    writing a program for a quiz. what happens is that you are given a menu and you choose the level of difficulty you want. Then the next menu asks if you want to do random operator or asks you to enter an operator. i'm confused as to how i write code for my program to display the problems using a random operator. this is what i have in my functions.cpp file so far. also the error functions.cpp:89: error: expected initializer before â.â token is coming up in line 89.

    Code:
    #include <iostream>
    #include "functions.h"
    #include <cstdlib>
    
    using namespace std;
    
    void greet()
    {
      cout <<"Hello User! Welcome to..."<< endl;
      return;
    }
    
    void signoff()
    {
      cout <<"Goodbye User!" <<endl;
      return;
    }
    
    int menu()
    {  
      int option;
      int level;
       do
       {
        cout <<"Please select difficult level"<< endl
        <<"1. Easy"<< endl
        <<"2. Moderate"<< endl
        <<"3. Advanced"<< endl;
        cin >> option;
        if ( option < 1 || option > 3 )
        {
          cout << option <<" is not a valid option."<< endl;
        }
    
       }while ( option < 1 || option > 3 );
      return option;
      if ( option == 1)
      {
        level = 1;
      }
      if ( option == 2)
      {
        level = 2;
      }
      if ( option == 3 )
      {
        level = 3;
      }
      return level;
    }
    
    int operatorChoice()
    {
      int choice;
      do
      {
        cout <<"Please choose an operator choice"<< endl
    	<<"OPERATOR CHOICE"<< endl
    	<<"1. I feel lucky - randomly picked operator"<< endl
    	<<"2. Pick a particular operator"<< endl;
    	cin >> choice;
    	if ( choice < 1 || choice > 2 )
    	{
    	  cout << choice <<"is not a valid option."<< endl;
    	}
      }while ( choice < 1 || choice > 2 );
      
      switch ( choice )
      {
      case 1:
        Problem generateProblemRand();
        break;
      case 2:
        Problem generateProblem();
        break;
      }
      return choice;
    }
    
    
    Problem generateProblemRand()
    {
      Problem result;
      char problem.m_arithmOp[4] = {'-','+','%','*'};
      return result;
    }
    
    Problem generateProblem()
    {
      cout<<"Please enter the operator you would like to use"<< endl;
      cin >> problem.m_arithmOp;
    }
    this is my struct in my header file
    Code:
    struct Problem
    {
      int m_number1;
      int m_number2;
      int m_answer;
      int m_level;
      char m_arithmOp;
    } problem;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    See your other thread
    random generator of chars help
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deallocating a struct containing arrays
    By maxtothemax in forum C Programming
    Replies: 5
    Last Post: 09-28-2009, 07:09 PM
  2. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  3. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 11:10 PM
  4. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  5. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM