I'm sure this is pretty standard, but I need to make a program that uses user input to perform a selected calculation. It has multiple files (this is the functions file, it also has a main file, which is definitely correct, and a header file). My errors are that I have multiple definitions of main, even though I only used the word main once (in the main file).
Also, it says in line 6 that I have no return in a function returning non-void. How do I fix these.
It's long so this is just a section, i've only cut out a few operations though. Am I missing anything?
You obviously did define main more than once or you would not be getting that error.
I am going to guess that you tried to write main() as a list of function calls and over complicating everything in the progress also.
1 2 3 4 5 6 7 8 9 10 11
// What purpose do the arguments serve?
// Number and Percentage are never used.
void perEntNum (double Number, double Percentage){
double N = 0.0;
double P = 0.0;
cout << "Enter Number: ";
cin << N;
count << "\n\n Enter Percentage out of 100: ";
cin << P;
cout << "\n\n Resulting Amount: " <<N*P/100<<endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// What purpose does this function even have?
void iDiv (double Numerator, double Denominator){
double N = 0.0;
double D = 0.0;
cout << "Enter Number 1: ";
cin << N;
count << "\n\n Enter Number 2: ";
cin << P;
cout << "\n\n Resulting Amount: " <<int(Numerator/Denominator)<<endl;
}
// Could be simplified to
void iDiv (double Numerator, double Denominator){
cout << "\n\n Resulting Amount: " <<int(Numerator/Denominator)<<endl;
}
// since all it does is get unused input from the user
// or better yet just write the cout statement in place of the function call
// it would be easier to see that you equation is equal to 0 / 0 that way
With all the mismatches and unused variables in this part it is very likely that you do have more than one main function.
You're welcome OP :) some times you can't take compiler errors for face value.
Please post your Source File
1 2 3 4 5 6 7 8 9 10
void iDiv (double Numerator, double Denominator){
double N = 0.0;
double D = 0.0;
cout << "Enter Number 1: ";
cin << N;
count << "\n\n Enter Number 2: "; // Here should be cout you have count
cin << P;
cout << "\n\n Resulting Amount: " <<int(Numerator/Denominator)<<endl; // what are you doing here?
}
1 2 3 4 5 6 7 8 9
void perEntNum (double Number, double Percentage){
double N = 0.0;
double P = 0.0;
cout << "Enter Number: ";
cin << N;
count << "\n\n Enter Percentage out of 100: ";
cin << P;
cout << "\n\n Resulting Amount: " <<N*P/100<<endl;
}
Unfortunately I do not have the computer with the other files with me. I think though, that they just tell this to run. It doesn't do anything different. (The spelling errors are for the same reason, I am just typing out the code here rather than copying and pasting)
What I am trying to do there is complete a division between any two numbers and change the answer to an integer. Obviously that is not what is actually happening though
Ok i think i know what you mean. I gave you 2 examples on how you can structure a function. i hope you find this useful. If you have any questions please ask.
#include <iostream>
usingnamespace std;
void divFrac() // no need for functions parameters here nothing going into function
{
int N;
int D;
cout << "Enter first Num" << endl;
cin >> N ;
cout << "Enter second Num" << endl;
cin >> D;
cout << "Result: " << (int)(N/D) << endl;
}
void divFrac2(int N, int D) // Passing Parameters to function example
{
cout << "Result " << (int) (N/D) << endl;
}
int main()
{
// no parameters needed for this function
divFrac();
// Passing Parameters to function example
int firstnum;
int secondnum;
cout << "Enter first Num" << endl;
cin >> firstnum ;
cout << "Enter second Num" << endl;
cin >> secondnum;
divFrac2(firstnum,secondnum); // this function takes in 2 ints (int, int)
return 0;
}
The spelling errors are for the same reason, I am just typing out the code here rather than copying and pasting
That is like saying "my program looks something like this" compared to "this is my program". Spelling, punctuation, case, and many other things make a big difference! You are just wasting the time of the people that are are trying to help you if you do not post what your code really is.