In: Computer Science
Hello, I keep getting the error C4430: missing type specifier -
int assumed. Note: C++ does not support default-int for my code.
What am I doing wrong? I only have #include
<iostream>
int read_num(void);
main()
{
int num1, num2, max;
//find maximum of two 2 numbers
num1 = read_num();
num2 = read_num();
if (num1 > num2)
{
max = num1;
}
else
{
max = num2;
}
printf("the maximum number is: %d\n", max);
return;
}
int read_num(void)
{
int num;
printf("Enter a number: ");
scanf_s("%d", &num);
return (num);
}
#include <iostream>
int read_num(void);
int main()//main() is a method and it should have some return type, so int is places before main()
{
int num1, num2, max;
//find maximum of two 2 numbers
num1 = read_num();
num2 = read_num();
if (num1 > num2)
{
max = num1;
}
else
{
max = num2;
}
printf("the maximum number is: %d\n", max);
return 0;//since main is of type int here it should return some value if the code doesn't have any errors here it returns 0
}
int read_num(void)
{
int num;
printf("Enter a number: ");
scanf("%d", &num);//scanf_s() is not a function for reading a number so..please correct this as scanf function
return (num);
}
corrections in the code were done and explanation is given in the form of comments inside the code where the code has corrections
and the output for the above code will be as follows
since the above code has no
errors, after displaying the output the code exited with the value
0