-1

The project is to write a program that reads three integers and then prints them in order read and reversed. use four functions: main, one to read the data, one to print them in the order read, and one to print them reversed I get the errors:

In fuction 'main':

[Error] expected declaration or statement at end of input

recipe for target 'main.o' failed

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, 
system("pause") or input loop */

int main(int argc, char *argv[]) {

int getData ( );
void printForward (int first, int second, int third);
void printReversed (int first, int second, int third);

int main (void)
{

int a;
int b;
int c;

a=getData();
b=getData();
c=getData();
printForward ( a, b, c);
printReversed ( a, b, c);

int getData();
{

int num;
printf ("Enter an integer: ");
scanf ("%d", &num);
return num;
} 

void printForward (int a, int b, int c);

{ 
printf ("\nNumbers in order: %d, %d, and %d\n", a, b, c);
return;
}

void printReversed (int a, int b, int c);
{
printf ("\nNumbers reversed: %d, %d, and %d\n",
c, b, a);
return;
}   
return 0;
}
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
zxnm
  • 1
  • 1
  • 3
    You seem to want to have nested functions. That's not possible. Functions need to be defined in the global scope, outside of any other functions. Perhaps you should [get a couple of good beginners books to read](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list)? – Some programmer dude Dec 04 '17 at 15:53
  • Please lear how to indent C programs properly. This is absolutely essential. – Jabberwocky Dec 04 '17 at 16:08
  • when I add } it gives me more errors printForward ( a, b, c); printReversed ( a, b, c); } // THIS RIGHT HERE – zxnm Dec 04 '17 at 16:47

3 Answers3

0

Seems like you are missing a simple } closing your main function. This would be more simple to observe if, and I cannot stress this enough, you used indentations in your code. This is something you should really think about doing more, it will help you, and others, with the readability of your code.

int main (void)
{

    int a;
    int b;
    int c;

    a=getData();
    b=getData();
    c=getData();
    printForward ( a, b, c);
    printReversed ( a, b, c);
} // THIS RIGHT HERE

int getData();
{
   // rest is the same
Zionsof
  • 1,196
  • 11
  • 23
0

Besides your nested function definitions there are lots of stray semicolons in your function definitions. Even if your compiler allows nested functions, you need to remove those

int getData();  <<<<===== remove trailing ;
{
...
}

Same for printReversed and printForward.

Gerhardh
  • 11,688
  • 4
  • 17
  • 39
0

I dont know why you are using command line argument, if the requirement of your project is to use four functions . I have given the following code which will work for your project. There is no need of writing two seperate functions for forward data and reverse data. You can do it by using same function for both. Just passing tha value will be reverse. dont use semicolon in the first line of function definition.