#include <iostream>
usingnamespace std;
int main ()
{
double x, y ;
cout<<"Please enter the value for \"x\", this program will prints the value of \"y\""<<endl;
cin>>x ;
if (x==0) y= x+2 ;
elseif (x>0) y= x-6 ;
elseif (x<0) y= 1/3(x+1) ;
elseif (x==-1)
cout <<" The value of denominator is 0, math error, please enter other value " <<endl;
else ;
cout <<"the value of \"y\" is"<<y<<endl ;
return 0;
}
I am doing my assignment, the compiler give error but I just dont know where it is -______-"
compiler give : 1>d:\desktop\cs115\assignment 1\assignment 1\question 1.cpp(10) : error C2064: term does not evaluate to a function taking 1 arguments
You will never reach line 2 like this, because if x == -1, x < 0, and if x < 0, your program will never check for x == -1.
Maybe you may want to invert their order like this:
// ------------------------------
// This prog gets a DEPTH, and returns Celsius
// and Farenheit Temps.
// version #:
// written by:
// date written:
//
// modified to change local vars to global ones.
// and added local vars within functions as temp vars.
//---------------------------------------
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
// Init'l the vars outside of main to make them global
// this way they can still be 'seen' inside of functions.
// Can be combined, but seperate until finished testing.
int depth = 0;
float cel = 0.0;
float fer = 0.0;
int main (void){
printf("\nPlease enter depth (in kilometres) inside the earth : ");
scanf_s( "%d", &depth );
printf("\nHi dear, my name is Farah.\n");
printf("\nFor the depth of %d km, the temperatures are: ", depth);
printf("\n%.2f degrees Celsius or %.2f degrees Fahrenheit.\n\n", cel, fer);
system("PAUSE");
return (0);
}
float celsius_at_depth (int d, float c)
{
// Created a temp var to hold the calculation
// when ready, moved the temp var to the live-one
// to be returned & to be printed.
float val_celsius = (10 * d)+ 20;
cel = val_celsius;
return cel;
}
float fahrenheit_at_depth (float c, float f)
{
// Created a temp var to hold the calculation
// when ready, moved the temp var to the live-one
// to be returned & to be printed.
float val_fahrenheit = (1.8 * c )+ 32;
fer = val_fahrenheit;
return fer;
}
//the problem is the celsius and farenheit is not compile???