im practicing a code i made up ( id o realize it does not make sense but the purpose of it is to see if the void type and functions work. now everything is working but the void function does not execute whats wrong here. please help
The first thing that I'll say is that you REALLY need to learn to indent properly. It is an imperative part of a program and a failure to do so will result in a misunderstanding or more difficult understanding of your code when you or someone else tries to re-read it. But a flow-understanding doesn't seem to be your main problem (though I see some strange things there that I would question).
Take a look at void totalprice(int total). I see that you declare a local variable and set it to total*10. What happens after that? We discard the local variable and return to the main function. The function didn't output anything, it just executed a line of code, then discarded any calculation. What did you want to happen here? What were you looking for? If you were expecting something displayed on the console, you need to put a cout, if you were expecting to modify something in main, you need to return a value.
int main()
{
// Mains scope
if (something)
{
// If's scope
}
// Back to mains scope
for (something)
{
// First For's scope
for (something)
{
// Second For's Scope
if (something)
{
// If's scope
}
}
}
}
Notice how each of the braces line up to eachother also. Now when we look at your indentation it is going way off to the right and isn't consistent (Meaning some are indented farther or less in the same scope).
ok i see so you say 4 spaces which is pretty much Hitting tab once for each scope indentation. i really appreciate the insight im going to be more organized with my codes from now on. thanks. i actually have another question how would i be able to input a longer number for the phone number because when the program asks for a phone number; if you input more than 7 numbers the program goes haywire i used long thinking it would allow me to do this but it didnt any recommendations?
To hold a phone number I would recommend using the std::string type to hold it. That why you can garuntee that it can hold the phone number and it can also support phone numbers in this format 1-800-654-342.
Here is how you can do it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <string> // You need this to use the string type
usingnamespace std;
int main()
{
string phoneNumber;
cout << "Enter your phone number: ";
cin >> phoneNumber;
cout << "Your phone number is: " << phoneNumber;
}
I would recommend setting up your editor to replace tabs with 4 spaces. The code tags on this site seem to make tabs 8 spaces - which makes it look worse than what's shown in your IDE. Or are you using a basic editor?
Can you do auto formatting / indenting on your IDE / editor - that is no need to press tab at all?