0

Why when i run the program the error say that i cant use it as a function

Exp totalrent=calcrent() error: calcrent cannot be use as function

15th Dec 2017, 7:02 AM
amirah balqis
amirah balqis - avatar
25 Answers
+ 4
There is so much wrong with the code I don't really know where to start to help you. I'm trying to make sense out of it, but not sure of your intent in some places. I guess we can start with the main function. First, I would suggest that you try to declare you variables as close to where they are first needed as possible. This will greatly reduce errors and increase readability, especially while you're learning. Also, use spacing to your advantage to make you code more readable for yourself and others. Second, a function prototype consists of its modifiers, return type, and signature. So, for your current price1 function: void price1(int quantity, double priceU); would be its prototype. Notice it ends with a semi-colon and doesn't include its body (everything between the curly braces and the braces themselves) Third, you don't declare the name of a function as a variable as well. You had calcrent, price1, price2, and totalmenu all declared as a float as well as a function. This will create a naming conflict and lead to errors. Fourth, you also have declares and set a couple a variables within the main function that are not used within this function. Fifth, you also have a couple of variables that are declared and then used prior to ever having a value set to them. Sixth, you have: return 0; system ("pause"); outside of any function/class etc at the end of your code. return 0; looks like it should be the last line in your main function. system("pause") will never be reached since it comes directly after a return statement. I've cleaned up the main function a bit and added some comments to show a couple of issues that remain. Look at the code to see the differences in readability, what has been removed, and what has been changed. I suggest you write out some notes in pseudo code so that you can refer to how it is your code should work and flow. Then write small amounts of code and test that it works the way it should before writing another small chunk and testing it. ......
15th Dec 2017, 8:47 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
open a window/tab in your browser go to https://www.sololearn.com click on Sign In enter the same login email and password you use for the app. click Sign In This should take you to your profile page scroll down to My Codes click + New Code this will open the code playground in a new tab/window select the language of the code that you want by clicking where it says HTML/CSS/JS unless you want web code in which case it is already selected. copy and paste your code into the editor click the Save button at the bottom of the page give your code a name click the public switch click save now click on the Share button to the right above the output window copy the link that is given click on the Discuss button at the top of the page this will open the forum in a new tab/window here you can click on the My Questions tab and find this post scroll down to the New Answer box and paste the link to your code click post
15th Dec 2017, 7:33 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Ok, so it looks like you are trying to set a value to a variable from a function that has a void return type. void calcrent( )
15th Dec 2017, 7:44 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Also, as @Corentin has stated you'll need to either rearrange your code or provide a prototype prior to the main function so that it is known to exist before it's use. I'll go over the code and post some needed changes if there are any more.
15th Dec 2017, 7:48 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
int main() { int MR; cout << "Please Enter Monthly Rent" << endl; cin >> MR; int qty; cout << "Please Enter Quantity" << endl; cin >> qty; float priceU; cout << "Please Enter Price Per Unit" << endl; cin >> priceU; int numS; // numS is set here but never used! cout << "Please Enter Number of serving" << endl; cin >> numS; float priceS; // priceS is set here but never used! cout << "Please Enter Price Per Serving" << endl; cin >> priceS; char Smenu; cout << "Please Enter Set Menu" << endl; cin >> Smenu; int numSmenu; cout << "Please Enter Number Of Set Menu" << endl; cin >> numSmenu; float totalR = calcrent(MR); // I'm guessing you really want to pass MR to this func float totalPrice = price1(qty, priceU); float totP = price2( ); float totalM = totalmenu(Smenu, numSmenu); float totalP, sum; // These are used, but never set cout << "Total Price Per Serving after discount:" << totalP << endl; cout << "Total Price:" << sum << endl; return 0; }
15th Dec 2017, 8:45 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Can you provide a link to the rest of the code.
15th Dec 2017, 7:05 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Nope, I don't use it. lol Also, this is a community of coders and programmers. Others may be able to help you as well. If you have the code saved in the playground, make it public and post a link to it here so we can help you. Otherwise, you can upload it somewhere such as github etc and post the link to the project.
15th Dec 2017, 7:11 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Copy and paste it in the code playground, then post a link.
15th Dec 2017, 7:13 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Login to the website in your browser on your laptop.
15th Dec 2017, 7:17 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
www.sololearn.com you log in with the same id/pass as in the app
15th Dec 2017, 7:36 AM
Corentin
Corentin - avatar
+ 1
done
15th Dec 2017, 7:42 AM
amirah balqis
amirah balqis - avatar
+ 1
OK. I think you have to define at least the prototype of that function before the main()
15th Dec 2017, 7:44 AM
Corentin
Corentin - avatar
+ 1
@ChaoticDawg thanks for the most helpful reply but please don't post your code as a comment, copy it in your playground and post a link, for the sake of comments readability.
15th Dec 2017, 8:51 AM
Corentin
Corentin - avatar
+ 1
thanks @chaoticDawg
15th Dec 2017, 9:04 AM
amirah balqis
amirah balqis - avatar
0
can i get your whatsapp number.. i want to sent the coding
15th Dec 2017, 7:07 AM
amirah balqis
amirah balqis - avatar
0
my coding in the laptop... so how can i upload it here
15th Dec 2017, 7:12 AM
amirah balqis
amirah balqis - avatar
0
how can i do that?? i use this app in my hp and the coding in my laptop
15th Dec 2017, 7:15 AM
amirah balqis
amirah balqis - avatar
0
what website
15th Dec 2017, 7:18 AM
amirah balqis
amirah balqis - avatar
0
can you teach me
15th Dec 2017, 7:18 AM
amirah balqis
amirah balqis - avatar
15th Dec 2017, 7:42 AM
amirah balqis
amirah balqis - avatar