Please i am new to C++ and need to understand basics....i have got a major assignment that would bee needing handing in by next week and still having problems of calling functions......this example below is something i just thought of out of the blues to use as an example to get explanations on how to call functions and also to avoid using the goto in coding as i hear that is bad practice........
can someone please put me through on calling functions and avoiding using goto in d example below:
You can call it like this: float p = psquare(my_a);. float p = part is optional, but you need to store the result somewhere. my_a is either a variable or a constant.
Now, in your code you probably want to print that perimeters, not return them. cout << "the perimeter is " << psquare(a) << '\n'; would do that.
In your code, goto end; doesn't do anything. If you removed it, the program would behave the same way.
Never call main(). You need a loop here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main(){
while(true){
//ask for input
if(d == 1){//...
}elseif(d == 2){//...
}else{
cout << "invalid!";
continue;//skip the rest of the loop. you could also just
//have another while loop around this if else block..
}
cout << "again?";
cin >> n;
if(n == 'n') break;//exit the loop if use enters 'n'
}
return 0;
}