473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

call of nonfuncytion in function main()

#include<iostream.h>
#include<fstream.h>
main()
{
char date[15], circle[10], filename[10], filename2[10], ans, write;
int bil,i;
double r[10], area[20], perimeter[15], pow[10];
const double pi=3.1415926535897932384626433832795;
again:
cout<<"\n enter data filename:";
cin>>filename;
// protocol read file
ifstream fp1;
fp1.open(filename);
if(!fp1)
{
cout<<"\n cannot open"<<filename<<"to read";
cout<<"\n continue read file?Y/N";
cin>>ans;
if(ans=='y'||'Y')goto again;
return 0;
}
cout<<"file found";//if file found

//read data
fp1>> date;
fp1>> circle;
fp1>> bil;

for(i=1; i<=bil; i++)
{
fp1>>r[i];
}

//display data on screen
cout<<"\ndate:"<<date;
cout<<"\n\nradius:";

for(i=1; i<=bil; i++)
{
cout<<"\n"<<r[i];
}

fp1.close();

//write to file(lab 6c)

//process
for(i=1; i<=bil; i++)
{
area[i]=pi*(pow(r[i],2));
perimeter[i]=2*(pi*r[i]);
}
//write data to file
cout<<"\nwrite data to file? Y/N";
cin>>write;
if(write=='y'||write=='Y')goto next;
return 0;
next:
cout<<"enter filename output name:";
cin>>filename2;

//protocol write to file
ofstream fp2;
fp2.open(filename2);
if(!fp2)
{
cout<<"\n cannot write to file"<< filename2;
}

fp2<<"\ndate:"<<date;
fp2<<"\n\nradius:"<<"\t\tarea:"<<"\t\tperimeter:";

for(i=1; i<=bil; i++)
{
fp2<<"\n"<<r[i]<<"\t\t\t\t"<<area[i]<<"\t\t\t\t"<<perimeter[i];
}
cout<<"\n file write successfully";
cout<<"\n open file output to read";
fp2.close();
return 0;
}
Dec 19 '11 #1
2 1365
weaknessforcats
9,208 Expert Mod 8TB
At first glance I see an array pow[10].

There is a library function named pow to caculate the power of a number. I expect your array name cannot be pow unless you create a namespace for yourself and put the pow array inside the namespace.
Dec 19 '11 #2
donbock
2,426 Expert 2GB
I don't know about C++, but you can't get away with this in C:
Expand|Select|Wrap|Line Numbers
  1. if(ans=='y'||'Y')goto again;
You have many opportunities for buffer overflow.

You print an error message if you can't open fp2, but then you fall into the code that writes to fp2.

As weaknessforcats suggests, the real culprit is this line:
Expand|Select|Wrap|Line Numbers
  1. area[i]=pi*(pow(r[i],2));
It suggests that "pow" is a function, when you earlier declared pow to be an array of double. Hence you get an error saying that you tried to call a nonfunction.
Dec 19 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Andrzej | last post by:
Is it possible to call a function which name is given by a string? Let assume that I created a program which call some functions for example void f1(void), void f2(void), void f3(void). ...
7
by: Rajan | last post by:
Hi All C++ experts My problem is regarding calling templatise class function please see the code snip shot #include<iostream> using namespace std void fun(char*);
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
1
by: Sandeep Chikkerur | last post by:
Hi, How do I call a function from one project to a function in another project? e.g. In VC++ environment, if u've two different projects , say proj1 & proj2 /****************************...
7
by: Steven | last post by:
I'm novice in C#. Here is a basic question -- I have 4 variables a, b, c, d in class main(). I want to perform all the mathematical operations on these variables in a function called maths() and...
9
by: matrim | last post by:
How do I call a function outside of main or use a parameter to pass a reference? If my function is: void getData(int& diameter, int& price) { cout << "Enter in the diameter of the pizza...
1
by: ckb | last post by:
Hi, I have an html page that has a javascript function that populates a dropdown list on the main html page. Ihave written a function that opens up a new window on a button click on the main window...
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
11
by: dolphin | last post by:
Hi All! I have a question that how to call a function just using a string. For example There is a .cpp file named a.cpp.There are some functions::fun1() fun2() fun3(). I have another fucntion...
12
by: aaragon | last post by:
I have this scenario: several arrays for which I have their fixed values at compilation time. Now, at runtime I need to access a specific array depending on an integer but I want to avoid if and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.