illegal else without matching if help?

Posts 1–6 of 6 · Page 1 of 1
illegal else without matching if help?
I made this program that calculates (a+b)/2
if c=0 and (a+b+c)/3 if d=0 and etc, and my visual studio says illegal else without matching if and i don`t know what to do, sorry if it is in my language but it is homework for after vacation!
http://pastebin.com/up6V5t9rⓘ
i can explain everything here!
i know that i can`t type 0 at more than one int and i have there a cout with instructions saying that you need to type 0 after the number you wanna stop and at everything else after type 1!

- - - Updated - - -

i debugged it... didn`t need to put ; after if, admin close thread please!
What's the point of * cout<< " " *
Quote Originally Posted by Senpai* View Post
What's the point of * cout<< " " *
there is no point , an else statement can be empty?
Quote Originally Posted by robertpopa09 View Post
there is no point , an else statement can be empty?
U can use if statement without "else" or "else if"
What the hell is this, turbo c++?
This is a better way to do it in my opinion.

Code:
#include <iostream>
#include <windows.h>
//Get used to living without 'using namespace std', it's for the best

int main()
{
	int N, Array[50], Sum = NULL;
	std::cout << "How many numbers do you want to use: ";
	std::cin >> N;
	std::cout << "Enter " << N << " numbers :";
	for (unsigned int i = 0; i < N; i++) //Unsigned 'cause it's always positive, also for 'for statement', use google
	{
		std::cin >> Array[i];
		Sum += Array[i]; //Sum = Sum + Array[i]
	}
	system("cls"); //Clears screen
	unsigned int ArrithmeticMean = Sum / N;
	std::cout << "Result is " << ArrithmeticMean << ".";
	Sleep(10000); //Waits 10 seconds, then exits, I tried using std::cin.get() or std::cin.ignore() but It doesn't work
}
if (c == 0);
if (d == 0);

and so forth.

The semicolon ends the if statements immediately. The brackets are not part of the if statements anymore and therefore your else if is not part of the if statement either.

Remove the semicolon (;) after each if ( bla );.
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us