-8

i am attending a online competition. my code is working in my compilier visual studio 2013. but the online judges giving me compilation error. here is my code.

    #include<iostream>
#include<string>
#include<cmath>
#include<fstream>
using namespace std;

void main() {

    int first_number;
    int  second_number;

    string str;
    char ch;
    int count = 0;

    ifstream yfile("q4.txt");

    while (!yfile.eof())
    { 
        yfile >>first_number;

        if (first_number < 0)
            first_number = abs(first_number);

        yfile >> ch;
        yfile >> second_number;

        if (second_number < 0)
            second_number = abs(second_number);

        int  gcd;
        for (int i = 1; i <= first_number&&i <= second_number; i++){


            if (first_number%i == 0 && second_number%i == 0){

                gcd = i;

            }

        }

        cout << "Output:    " << gcd << endl;



    }

can anyone please tell me solution? I will be thankful to you. }

Amad
  • 314
  • 1
  • 6
  • 25
  • 4
    What compilation error do you get from online judge? – Zereges Nov 19 '16 at 09:31
  • they just responding "No- Compilation Error" – Amad Nov 19 '16 at 09:32
  • 3
    `void main() {` this is undefined behavior. Please use one of the valid entry points for a program. For example `int main() {`. – nvoigt Nov 19 '16 at 09:32
  • 1
    you have more `{` than `}` – M.M Nov 19 '16 at 09:33
  • ok.. I am checking – Amad Nov 19 '16 at 09:33
  • What compiler they uses? Try to download it and compile your program with it – Michael Nov 19 '16 at 09:35
  • @nvoigt: `void main()` is not just undefined behavior in C++, it's ill-formed (I think that's the right term). Some compilers might permit it -- unfortunately. – Keith Thompson Nov 19 '16 at 09:40
  • @KeithThompson: Can you recommend a good, authorative SO answer or other resource for the question about the difference between ill-formed and UB? In http://stackoverflow.com/questions/22180312/difference-between-undefined-behavior-and-ill-formed-no-diagnostic-message-requ, James Kanze once suggested that the difference is often not as clear as we'd like it to be. As for `main`, the C++ standard itself only uses the (IMO) vague term "shall" (*"It shall have a declared return type of type int"*). – Christian Hackl Nov 19 '16 at 10:34
  • @ChristianHackl: I'm much more familiar with the C standard than the C++ standard. The C standard clearly defines what the word "shall" means: in a constraint it specifies a rule whose violation must be diagnosed, and outside a constraint it specifies a rule whose violation causes undefined behavior. I haven't found a similar statement in the C++ standard (which doesn't mean it's not there). – Keith Thompson Nov 19 '16 at 21:02

1 Answers1

1
  1. The code posted has one missing curly brace at the end.

  2. error: ‘::main’ must return ‘int’
    Try using
    int main() {
    instead. And add a return 0; statement at the end (or whatever return value you want).

  • curly braces here is my mistake in posting code. I am trying int main(){} now. hope so it works – Amad Nov 19 '16 at 09:40