-
whats wrong here??
using vc++, trying to calculate area of triangle..
Code:
#include <iostream.h>
#include <conio.h>
int a,x,y,z;
int calcu(x,y)
{
z="0.5"*x*y;
return z;
}
int main()
{
cout<<"Enter base: ";
cin>>x;
cout<<"Enter height: ";
cin>>y;
calcu(x,y);
cout<<"Area="<<z;
cout<<"\nAgain? (y/n)";
cin>>a;
if a="y"
{
clrscr();
main();
}
return 0;
}
get errors:
Code:
D:\Programming\c\triangle calc\Cpp1.cpp(6) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
D:\Programming\c\triangle calc\Cpp1.cpp(16) : error C2065: 'calcu' : undeclared identifier
D:\Programming\c\triangle calc\Cpp1.cpp(20) : error C2061: syntax error : identifier 'a'
D:\Programming\c\triangle calc\Cpp1.cpp(21) : error C2143: syntax error : missing ';' before '{'
D:\Programming\c\triangle calc\Cpp1.cpp(22) : error C2065: 'clrscr' : undeclared identifier
10x thanks
-
I think you need to go read your book again
-
Code:
#include <iostream.h>
#include <conio.h>
int a,x,y,z;
int calcu(x,y)
{
z="0.5"/*<------ is a string. You're multiplying a string with a number.*/ *x*y;
return z;
}
int main()
{
cout<<"Enter base: ";
cin>>x;
cout<<"Enter height: ";
cin>>y;
calcu(x,y);
cout<<"Area="<<z;
cout<<"\nAgain? (y/n)";
cin>>a;
if a="y" Also a is an integer and you're trying to store a character in it. :confused: And calling main()????:confused:
{
clrscr();
main();
}
return 0;
}
Honestly. Do what salem said.
-
Re: whats wrong here??
Quote:
Originally posted by pico
using vc++, trying to calculate area of triangle..
Code:
#include <iostream.h>
#include <conio.h>
int a,x,y,z;
int calcu(x,y)
{
z="0.5"*x*y;
return z;
}
int main()
{
cout<<"Enter base: ";
cin>>x;
cout<<"Enter height: ";
cin>>y;
calcu(x,y);
cout<<"Area="<<z;
cout<<"\nAgain? (y/n)";
cin>>a;
if a="y"
{
clrscr();
main();
}
return 0;
}
get errors:
Code:
D:\Programming\c\triangle calc\Cpp1.cpp(6) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
D:\Programming\c\triangle calc\Cpp1.cpp(16) : error C2065: 'calcu' : undeclared identifier
D:\Programming\c\triangle calc\Cpp1.cpp(20) : error C2061: syntax error : identifier 'a'
D:\Programming\c\triangle calc\Cpp1.cpp(21) : error C2143: syntax error : missing ';' before '{'
D:\Programming\c\triangle calc\Cpp1.cpp(22) : error C2065: 'clrscr' : undeclared identifier
10x thanks
you have many errors man first of all function calcu u have to say
Code:
int calcu(int x,inty)
also a is character to integer !!!!!!
anyway i wrote a code for u ... i didnt run it so try to run it and see
Code:
#include<iostream>
using namespace std;
int main()
{
int x,y,z;
char a;
do
{
cout<<"enter base :\n";
cin>>x;
cout<<"enter height:\n";
cin>>y;
z=0.5*x*y;
cout<<"area of the triangle "<<z<<endl;
cout<<"enter y to continue \n";
cin>>a;
}
while((a=='y')||(a=='Y'));
return 0;
}
i think it will work :)
-
thanks M_Ghani for your ideas..
my final working code:
Code:
#include <iostream.h>
int x,y;
char a;
int calcu(int x,int y)
{
return 0.5*x*y;
}
int main()
{
do
{
cout<<"Enter base: ";
cin>>x;
cout<<"Enter height: ";
cin>>y;
cout<<"Area="<<calcu(x,y);
cout<<"\nAgain? (y/n)";
cin>>a;
}
while ((a=='y')||(a=='Y'));
return 0;
}