I really need help with making my own functions!

Hello i was wondering you can help me.Every time i try to make my own function so i can get user input it fails and doesnt compile.Example of my failed code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "stdafx.h"
#include <iostream>
using namespace std;
typedef unsigned short USHORT;
USHORT Find(Mass , Velocity)

int main()
{

USHORT onemass;
USHORT onevelocity;
USHORT Total;

cout << "What is your velocity?\n";
cin >> velocity;

cout << "what is your mass?";
cin >> mass;

Total = Find(onemass,onevelocity);

cout << "your total is:";
cout << Total;
cin.get();
return 0;


}
USHORT Find(USHORTMmass,USHORT Veocity)
{
	cin.get();
	return mass * velocity;
}


Can you help and tell me how i can i remember the right way in doing this

btw compile error

------ Build started: Project: latest function practice, Configuration: Debug Win32 ------
latest function practice.cpp
latest function practice.cpp(5): error C2065: 'Mass' : undeclared identifier
latest function practice.cpp(5): error C2065: 'Velocity' : undeclared identifier
latest function practice.cpp(7): error C2448: 'Find' : function-style initializer appears to be a function definition
latest function practice.cpp(15): error C2065: 'velocity' : undeclared identifier
latest function practice.cpp(18): error C2065: 'mass' : undeclared identifier
latest function practice.cpp(20): error C3861: 'Find': identifier not found
latest function practice.cpp(29): error C2065: 'USHORTMmass' : undeclared identifier
latest function practice.cpp(29): error C2275: 'USHORT' : illegal use of this type as an expression
latest function practice.cpp(4) : see declaration of 'USHORT'
latest function practice.cpp(29): error C2146: syntax error : missing ')' before identifier 'Veocity'
latest function practice.cpp(29): error C2078: too many initializers
latest function practice.cpp(29): error C2275: 'USHORT' : illegal use of this type as an expression
latest function practice.cpp(4) : see declaration of 'USHORT'
latest function practice.cpp(29): error C2059: syntax error : ')'
latest function practice.cpp(30): error C2143: syntax error : missing ';' before '{'
latest function practice.cpp(30): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Inserted comments into your code, read carefully and write your programs more carefully.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream> // stdafix.h is not necessary for this program.
using namespace std;
typedef unsigned short USHORT;
USHORT Find(USHORT Mass , USHORT Velocity); // the variable names are not required but the 
//variable type is. you must include USHORT, your prototype could also be USHORT Find(USHORT,USHORT);

int main()
{

USHORT onemass;
USHORT onevelocity;
USHORT Total;

cout << "What is your velocity?\n";
cin >> onevelocity; // assigning a value to velocity will not work because you haven't declare a 
//variable dubbed velocity, but you do have one called onevelocity, so lets use that.

cout << "what is your mass?";
cin >> onemass; // same problem as above, there is no mass variable in this program, lets use 
//onemass .

Total = Find(onemass,onevelocity); // your calculations would come out mumbo jumbo earlier 
//because you were passing onemass and onevelocity which were variables you declared but never 
//assigned a value, there value was whatever default values were stored in those memory locations.

cout << "your total is:";
cout << Total;
cin.get();
return 0;


}
USHORT Find(USHORT Mass ,USHORT Velocity) // typos, C++ is case sensitive & grammar means 
//serious business.
{
	return Mass * Velocity; // removed the pointless cin.get() statement, it added nothing to your
//function
}
Last edited on
Topic archived. No new replies allowed.