C :: Menu Driven Array Of Function Pointers Calculator

May 12, 2013

The premise of this assignment is to create a menu driven, array of functions calculator. This is the code I have thus far (I haven't finished all of my comments yet, I've been to focused on clearing errors).

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/*prototypes*/
void sum (int a, int b);
void dif (int a, int b);
void pro (int a, int b);
void quo (int a, int b);
void printMenu();

[Code] .....

I am using Visual Studio as a compiler, and I have the following errors:

error C2144: syntax error : 'int' should be preceded by ')'
error C2660: 'sum' : function does not take 0 arguments
error C2059: syntax error : ')'
error C2144: syntax error : 'int' should be preceded by ')'

[Code] .....

I can only assume that I am making simple mistakes.

View 4 Replies


ADVERTISEMENT

C/C++ :: Menu Driven Complex Calculations

Mar 18, 2015

//complxCalc.cpp//

#include "complx.h"
using namespace std;
ifstream infile ("in.dat");
int main() {
int i = 0;
complx tempComplx;
double d = 4.5;

[Code] ....

//in.dat//
(4,4) (6,7) (2.5, 9.3) (3,8.4) (13, 26.5) (2.2, 3.4)

My plan is to make this a menu driven program, I have already got the program to give the answers but now I want it to give the user choices as well. The first step in this project is to add a menu to the program. The first menu the user sees should ask the user if the program will be taking input from a file or from the user directly via the keyboard. Regardless of option chosen, the user should then be prompted to specify whether a multiplication,subtraction or addition operation should be performed.

If the user originally chose the file input method then the program should proceed to display to the screen the results of those operations on each pair of data elements in the file and terminate. If the user chose to input via the keyboard then the user should be prompted to input the two numbers, perform the operation on those two numbers and display the results to the screen and ask the user which mathematical operation they would like to do next and continue in this manner until the user chooses to exit the program via a menu option. Fortunately the only file that needs to be edited are in.dat and complxcalc.cpp files.

View 1 Replies View Related

C/C++ :: Menu Driven Program - Value Returning Functions

Apr 2, 2015

I'm working on what I thought was a pretty simple program. I'm writing a menu driven program that will allow users to obtain specified measurements of several geometric figures. I was trying to test each each time I add a function.

I keep getting this error. error C3861: 'AreaOfSquare': identifier not found.

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
int menu() {
int choice;

[Code] ....

View 4 Replies View Related

C++ :: Test Navigating With Arrows In Menu Driven Program

Aug 6, 2014

This is a program used to test navigating with arrows in a menu driven program

Whenever I run it it works but when I select any option it just producing a 'sound' but it doesn't print (cout) anything on the screen....

This program is just to test the arrow navigation and doesn't really modify,delete or add a new record but only prints stuff on screen.

#include<fstream.h> //for reading and writing files
#include<conio.h> //for clrscr()
#include<string.h> //for string characters
#include<stdio.h> //for gets and puts function

[Code] ....

View 7 Replies View Related

C :: Program That Have Starting Menu For A Calculator Using If / Else Statement

Sep 21, 2014

I just started learning C and trying to create a program in C that will have a starting menu for a calculator. The problem is that I could do that with a switch/case but the assignment requires me to use if/else.

Here's what I have so far:

Code:

#include <stdio.h>
int calc();
int menu();
int main() {
printf("Hello. Welcome to the program.
");
printf("Press RETURN key to continue...

[Code]...

How should I go from now using if/else to have those 4 choices?

View 5 Replies View Related

C++ :: Menu Program Broken Down Into Series Of Calls To Function For Each Of Menu Items

Aug 19, 2013

I am trying to write a menu program that will be broken down into a series of calls to function for each of the menu items. Two of the menu items will be simple programs which I wrote.

I want two of the functions to run one of the two programs I am trying to include as items in the menu.

So far I am only familiar with variables, loops, if statements, and I just learned how to write functions.

The problem I am have is that I don't quite understand how to write a function that will run one of the two programs. Also I am having a hard time writing the program in away that would allow the user to select the menu items.

View 2 Replies View Related

C :: Static Array Of Function Pointers

Jan 29, 2015

I basically have some code that lets users register callbacks into a callback table at a specified index. There is one element in this table for each event that can trigger a callback. I basically do something like this:

In a header file

Code:
typedef struct _GMclient
{
GMcommunicator gcomm;
GMclient_callback callback_table[(int)MAX_CALLBACKS];
}GMclient;

typedef int (*GMclient_callback)(GMclient*, void*, void*);

Then I allow them to set the callback with a function that basically ends up doing this (in a .c file that includes the previous mentioned .h file):

Code:
void
GMclient_register_callback(GMclient *client,
GMclient_callback fxn,
int index)

[Code] ....

Then later when I need to invoke that callback, I pull it out of the table

Code: GMclient_callback *fxn = client->callback_table[CMD_INDEX];

However, I get compilation errors:

Code: src/gmanager_client.c:43:6:

error: a label can only be part of a statement and a declaration is not a statement...

View 4 Replies View Related

C :: How To Pass 2 Array Pointers To A Function

Aug 4, 2013

How would I pass let say 2 array pointers to a function X , allocate memory for them in X , fill them with values and get them back in my main function without creating a structure.

example:

Code:

void X(int *a, int*b){
a= malloc ...
b = malloc ...
// fill a and b
return them back to the main function
}
void main(){

[Code]...

View 3 Replies View Related

C++ :: Function Pointers Inside Array

Apr 6, 2014

Ive recently got into function pointers, i find that they can be quite handy for making your program very 'dynamic'.

However, the syntax is very confusing for what i want to do
This is what i want to do

I want to hold function pointers inside an array, but this array is dynamically allocated ( malloc, realloc, etc )

This is the current syntax ive come up with, but i dont think it is correct

void ( **drawFunc ) ( void*, SDL_Surface* );

View 2 Replies View Related

C :: Create Array Of Pointers To Pointers Which Will Point To Array Of Pointers

Feb 28, 2014

I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried

Code:

int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",

[code]...

the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..

View 4 Replies View Related

C++ :: Dynamically Allocated Array Of Function Pointers

Dec 13, 2013

I would like to know if this code is correct.

#include <iostream>
#include <string>
int say_one(const std::string &s) {
std::clog << s << ": One!

[Code] .....

View 7 Replies View Related

C++ :: Passing Array Of Pointers From A Function To Main

Nov 21, 2014

I have a a group of text files that are used as input into a program. Another very similar program needs the same data in a different input format. I am writing a program that will read in each line of data and parse it. I have successfully written the program in main() such that it will read until the end of file. However, I am trying to re-write the program such that the algorithm is in an external function and will read one line at a time and then pass all of the character strings to the main program. The program will not compile and I am positive it has to do with an incorrect use of arrays in passing the variable "token". I am attaching a copy of the main program and the function.

#include <iostream>
#include <fstream>
#include <cstring>
#include <stdio.h>
void Line_Parse(std::ifstream&,std::ostream&,const char* token);
int main(int argc, const char * argv[]) {

[Code] .....

View 2 Replies View Related

C/C++ :: Assigning Functions To Array Of Function Pointers

May 13, 2013

I'm trying to create an array of function pointers and then assign compartilbe functions to them, so I can just call *pf[0](xxx);

The functions are all of the type

void func01(unsigned char*, int, int)

how would I create an array of function pointers and assign the address of the functions to them? So I could call them like

ptrToFunction[i](charBuffer, 10, 20);

I've read a bit on line and I thought I could do it but so far I've failed.

It seems trivial and I feel I'm close but close isn't good enough.

I'd like to assign the fuction addresses like this:
for (int i=0; i<10; i++)
if (i==1)
ptrToFunction[i]=func01;
if (i==2)
ptrToFunction[i]=func02;
etc.

The actual logic is somewhat different than this but this close.

View 4 Replies View Related

C :: Declaring Pointer Variable To Array Of Function Pointers?

May 24, 2013

I am having following pointer variable declaration

Code: Static double (*funcs[]) (double) = { sin,cos,tan,asin,acos};

Here funcs is an array of pointers to functions which take double as input and gives double as output with static as storage type am I right.

View 2 Replies View Related

C++ :: Find Voltage By Multiplying Resistance And Current Array By Using Function And Pointers

Nov 11, 2013

I am suppose to find voltage by multiplying a resistance array and a current array by using a function and pointers. This is what I have so far:

#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>

[Code] ....

View 1 Replies View Related

C :: BMI Calculator With Added Function

Aug 17, 2013

getting error with gcc under OSX.

Code:

/* bmi2.c */
#include <stdio.h>
main()
{
float height, weight;

printf("Enter weight:
");

[code]....

View 2 Replies View Related

C++ ::  Calculator Program - Function Does Not Take 0 Arguments

Jan 29, 2014

I am supposed to get 2 numbers then have the person choose what they want to do to the numbers. Here is the code:

//Mike Karbowiak
//12/24/13
//Mathematics
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>

[Code] ....

The errors I am getting so far are:

error C2660: 'Add' : function does not take 0 arguments
error C2660: 'Subtract' : function does not take 0 arguments
error C2660: 'Multiply' : function does not take 0 arguments
error C2660: 'Divide' : function does not take 0 arguments

View 3 Replies View Related

C :: Program Based On Menu System - Option To Go Back To A Previous Menu

Apr 7, 2014

I'm creating a program that is based on a menu system. Basically each menu is its own user-defined function. The problem is at each menu you can input 'b' to go to the previous menu. I just have it call the function of that menu.

However, do the functions need to complete themselves eventually? If I just keep calling functions will I just keep going further and further deeper into ever running functions?

If so how do I avoid this and yet keep the option to go back to a previous menu/function?

View 2 Replies View Related

C++ :: How To Allow User To Input Operator Into Calculator Function

Aug 24, 2014

How I can let the user input a certain operator into this calculator function?. I would like to use cin to input the operator if possible because it is one of the only input commands I know.

// Calculator.cpp : Defines the entry point for the console application.
// Calculates the value of two numbers based on the four main operations.

#include "stdafx.h"
#include <iostream>
int add(int x, int y);
int subtract(int x, int y);
int multiply(int x, int y);
int divide(int x, int y);

[Code] ....

View 1 Replies View Related

C/C++ :: Basic Console Calculator - Void Function Getting Ignored?

Jun 16, 2014

I made a basic console calculator in C++ using the Code::Blocks IDE and using the GNU GCC compiler. The problem in my code is my void function called 'operate' is getting ignored by not showing up in the console. After the first if statement I added a user input by saying Y for yes or N for no. Another if statement inside the first one shows if you type either 'Y' or 'y' it will execute the 'operate' function which will restart the calculator by having the same selection menu as in the int main function. When I call the function it does not show up in the console but just ends the program.

Here is my code:

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int input,input2, numAdd, numAdd2, numSub, numSub2, numMult, numMult2, numDiv, numDiv2;
void operate() {
cout << "Select a operator." << endl;

[code].....

View 2 Replies View Related

C++ :: Two Way Event-driven Communication Between Objects

Oct 26, 2013

I need to implement a two-way asynchronous communication between two objects, not using any IPC.

What I have now is a producer-consumer model where producer sends a number "88" to consumer at random intervals. Now, I need consumer to send a number "99" back to producer at a random intervals, this probably should be done in a separate thread.

I am using GNU on Linux, here is the compile line.

Code:

g++ -g -std=c++11 main.cpp -o main

Code:

#include<iostream>
#include<chrono>
#include<thread>
class IObject {
public:
virtual void fromApp(int i) = 0;
virtual int toApp(int& i) = 0;// ???

[code].....

View 8 Replies View Related

C++ :: How To Set Up Prime Function Program Within Menu

Oct 16, 2013

Can not seem to get the program to perform the calculations within the cases. Also, how do you set up the a prime function program within the menu. Have been trying for five days now.

#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
void showChoices();
double prime(double, double);
double abs(double, double);
double pow(double, double);

[Code]...

View 1 Replies View Related

C++ :: Setting Up Menu (With 4 Options) As A Function

Mar 4, 2014

I am having problems with setting up a menu as a function. The point of the menu is to display a list of 4 options and the user is supposed to choose one option and then the program will run. I am having trouble understanding how to display the menu once I run it because it is not working.

#include <iostream>
using namespace std;
int menu(int ans); // function declaration for menu
void draw_triangle(int size, char ch); //function declaration for triangle
void draw_downtri( int size, char ch); // function declaration for upside-down triangle
void draw_diamond(int size, char ch); //function declaration for diamond

[Code] ....

View 1 Replies View Related

C/C++ :: Creating A Menu That Will Return The Menu After A Selection

Apr 7, 2014

This is what I have so far, it gives me a nice menu to select from and it all works but after I make a selection it closes the program. I tried to return to it but it won't work for me

#include <stdio.h>
int main() {
int choice;
int deposit;
int balance = 500; {
printf(" CHOOSE FROM THE FOLLOWING

[code]....

View 14 Replies View Related

C++ :: Multi-level Algorithms For Date-driven Scheduling

Apr 18, 2012

What is Multi-level algorithms for date-driven scheduling?

View 8 Replies View Related

Visual C++ :: How To Modify System Menu To Execute A Function

Feb 11, 2013

I wish to add the item 'Website' to an MFC Dialog app System Menu so that it can activate the following method:

Code:
void CMyDlg::OnWebpage()
{
ShellExecute( NULL, NULL, _T("[URL]..."), NULL, NULL, 0 );
}// OnWebpage()
I have tried this:

Code:

#define IDM_WEBSITE (WM_USER + 101)
//..
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
pSysMenu->AppendMenuW(MF_STRING, IDM_WEBSITE, _T("Website"));
}

[Code]...

The code compiles without error but and the 'website' item appears on the System Menu but it doesnt do anything.

I've inspected the following but don't really understand how it works and it seems to me there should be a simpler way to accomplish my end.

Modifying the System Menu By John Simmons 26 Jan 2007 [URL]....

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved