Functions (pass by value/pass by reference)

Hello, I'm having some issues with my program and I'm not entirely show on what is wrong. Guidance or tips on my program would be appreciated

#include "pch.h"
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;


int main()
{
//Declare Variables
double amount = 22.66;
int num;
int dollars;
int quarters;
int dimes;
int nickels;
int pennies;
double x = 22.25;
double y = 55.55;

//Input
cout << "Please enter your dollar amount: ";
cin >> amount;

void showMenu(); //function prototype
{

cout << "A. Money Exchange function" << endl;
cout << "B. Find Max Solution" << endl;
cout << "E. Exit" << endl;
cout <<"Please eneter your choice:"<<endl;
}

void MoneyExchange(float amount, int& dollars, int& quarters, int& dimes, int & nickels, int & pennies); // function prototype
{
int amount = 0, Remainder;
amount = amount * 100;
dollars = amount / 100;
Remainder = amount - (dollars * 100);
quarters = Remainder / 25;
Remainder = Remainder - (quarters * 25);
dimes = Remainder / 10;
Remainder = Remainder - (dimes * 10);
nickels = Remainder / 5;
Remainder = Remainder - (nickels * 5);
pennies = Remainder / 1;
}

double max(double x, double y); //function prototype
{
double max;

if (x >= y)
max = x;
else
max = y;
}

system("Pause"); //pause the screen
return 0;
}
You're trying to create functions inside other functions. You can't do that.

Move your function definitions out of the main function.
Can you provide an example? I believe I moved the function definitions
http://www.cplusplus.com/doc/tutorial/functions/

1
2
3
4
5
6
7
8
9
10
11
12
13

// Define a function
double foo(double llama) // NOTICE:  NO SEMI-COLON HERE
{
    return 2.0 * llama;
}

// Call a function, from main
int main()
{
    double ama = 21.0;
    ama = foo(ama); // call the function.
}


Notice the lack of semi-colons during the definition of the foo function itself (no semi-colon after the set of parentheses).
Can you provide an example? I believe I moved the function definitions


Here is the structure of your main function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
  // some variables

  // input

  definition of function  showMenu

  definition of function  MoneyExchange

  definition of function  max

  system("Pause"); //pause the screen
  return 0;
} 


See those function definitions INSIDE main? That's bad. Don't do that.
I was able to fix those errors, but I am not sure on how to add my functions to my main. What would the functions be?
being extra explicit, you just want this style generally:

int foo(); //header, this often goes in a .h file in bigger programs.

int main()
{
foo(); //use it is ok, but the function body goes outside as shown here.
}

int foo() //function body. this often goes in a cpp file apart from main's file.
{
code;
}

What would the functions be?

Why would they be any different from the ones you've already written? No-one's telling you your function definitions are wrong. We're just telling you that you shouldn't put them inside your main() function.
Topic archived. No new replies allowed.