Reputation: 61
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include "bcio2.h"
int error, x;
char totalimpulse[80], averageimpulse[80];
void validate_number();
int main(void)
{
clrscr();
do{
printf("\nTotal Impulse delivered: ");
gets(totalimpulse);
validate_number();
} while (error != 0);
printf("You entry %d was valid\n", x);
getch();
return 0;
}
{ //error C2447
clrscr();
do{
printf("\nAverage Impulse delivered: ");
gets(averageimpulse);
validate_number();
} while (error != 0);
printf("You entry %d was valid\n", x);
getch();
return 0;
}
The brackets seen to match and there doesn't seem to be any unnecessary semicolons. I'm assuming this is the correct way to display input/validation. It works fine when run with just the do…while(); loop for totalimpulse but when I copy/paste the exact same between another pair of { } I get just that C2447 error.
Upvotes: 1
Views: 402
Reputation: 49896
The code that starts where the error is is not inside main
, or any other function for that matter. If you remove the braces on the error line and the one preceding it, then your second loop will also beside of main
. If you want that section to be a different function, you have to include the header for that function. What you put at the top for validate_number
is just a promise that you will define that function somewhere (although if you mean for that section at the bottom to be validate_number
, I'm pretty sure you don't want it to be recursive).
Upvotes: 1
Reputation: 137497
Right now you just have a block of code, outside any function.
I'm assuming from the rest of your code, that this block of code is supposed to be the definition of void validate_number();
, like this:
void validate_number()
{
clrscr();
do{
// ...
return 0;
}
Do note that a void
function cannot return a value, so your return 0
should be removed.
Upvotes: 1