whats wrong here??

This is a discussion on whats wrong here?? within the C++ Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    29

    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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    I think you need to go read your book again
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    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.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    127

    Re: whats wrong here??

    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

  5. #5
    Registered User
    Join Date
    Feb 2004
    Posts
    29
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21