Question
Can someone fix my error. Is there a way where I do not need to convert in c99 mode and maintain it to c90. Can
Can someone fix my error. Is there a way where I do not need to convert in c99 mode and maintain it to c90. Can you change the for-loop to while loop or do-while loop?
Here is my code:
// Used for input and output functions #include
// Function declaraction to take input from user int user_interface(); // Function declaraction to check a number is even or odd int is_even(int num); // Fucntion declaraction to print data in table form void print_table(int max);
//Driver function int main(int argc, char* argv[]) { // Varibale to store a number int num; // Call function to read user input num = user_interface(); // Call function to print the table print_table(num); return 0; }
// This function reads a maximum number from user until a valid input is obtained int user_interface() { // Header printf("This prints first N numbers entered by user and whether it's even or odd "); printf("------------------------------------------------------------------------- "); // Variable used to store number form user int num; // Loop until valid input is entered while(1) { // Take a number form user printf("Enter maximum number to show: "); scanf("%d",&num); // If number is greater than 0 if(num > 0) // Exit from loop break; // If number is less than 0. Take another input else printf("Invalid input! Please enter an integer! "); } // Return the number entered by user return num; }
// Function to check number is even or odd // Returns 1 if given number is even and 0 if odd int is_even(int num) { // If number is divisible by 2 if(num % 2 == 0) // Return 1 return 1; // If number is not divisible by 2 else // Return 0 return 0; } // Function to print the numbers in table format void print_table(int max) { printf("%s","Number"); printf("%15s ","Odd/Even"); // Loop till maximum number for(int i = 0; i
Here is the error: Please fix all the possible error thanks.
uhx02:/home/d/davidron/homework2% gcc -ansi -pedantic-errors -Wall -c homework2.c homework2.c: In function 'user interface' : homework2.c:78:4: error: ISO 690 forbids mixed declarations and code [-Wpedantic] int num; homework2.c: In function 'print_table': homework2.c:122:5: error: 'for' loop initial declarations are only allowed in 099 mode for(int i = 0; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started