math progeram not working

Started by
4 comments, last by headshot 21 years, 2 months ago
well i was trying to learn fucshions so i dsided to rewright a math progeram i did a wile back here it is
  
//um,  ok this progeram takes to numbers and eather adds, subtacts,  multiplies,  or diveds

#include <iostream.h>
#include <stdio.h>



int plus(int a,  int b)//this does +,  i will pass it the numbers i want it to use

{
	return a+b;
}



int minus(int a,  int b)//does -

{
	return a-b;
}
 



 int times(int a,  int b)//does *

{
	return a*b;
}



int dived(int a,  int b)//does /

{
	return a/b;
}

int main()
{


	int num1;//first number

	int num2;//2nd number

	char op;//what to do with them

	int answer;


cout << "give me a number";//get the first number

cin >> num1;

cout << "give me one more";//get 2nd number

cin >> num2;

cout << "what do you want to do with them";
cin >> op;


if (op == "+")
{
answer = plus(num1, num2);
}

if (op == "-")
{
answer = minus(num1, num2);
}

if (op == "*")
{
answer = times(num1, num2);
}

if (op == "/")
{
answer = dived(num1, num2);
}

cout << answer
cout << endl
return 0
}


  
here is the error c:\program files\microsoft visual studio\myprojects\math8\math8.cpp(78) : fatal error C1010: unexpected end of file while looking for precompiled header directive did i miss a header?
i am god!
Advertisement
Try changing all of the double quotes around the math symbols(ie, "+", "-" to single quotes.(ie, ''+'' , ''-'') in the if statements. You are passing a char *, not a char.

Also, you don''t have any semicolons on the last three statements.
cout << answer << endl;return 0; 

works.
On the wall I face when I sit in front of the computer I have put up a paper whereon in huge letters is written:

BEFORE TEARING YOUR HAIRS OUT :
- CHECK FOR MISSING '';''
- MAKE SURE YOU HAVE ''=='' NOT ''='' FOR COMPARISONS

Kronos
add

#include "stdafx.h"

at the top of the file ( if using msvc which i assume you are :-) )

[Insert cool signature here]
[Insert cool signature here]
It worked fine for me without including -#include "stdafx.h"-

I changed all "" to single '''' so instead of "+" do ''+'', and also as someone already mentioned your missing 3 semicolons at the end.
thanks a lot guys!!!!! it works now
i am god!

This topic is closed to new replies.

Advertisement