//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
}
math progeram not working
well i was trying to learn fucshions so i dsided to rewright a math progeram i did a wile back here it is
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?
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.
works.
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
BEFORE TEARING YOUR HAIRS OUT :
- CHECK FOR MISSING '';''
- MAKE SURE YOU HAVE ''=='' NOT ''='' FOR COMPARISONS
add
#include "stdafx.h"
at the top of the file ( if using msvc which i assume you are :-) )
[Insert cool signature here]
#include "stdafx.h"
at the top of the file ( if using msvc which i assume you are :-) )
[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.
I changed all "" to single '''' so instead of "+" do ''+'', and also as someone already mentioned your missing 3 semicolons at the end.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement