473,395 Members | 1,856 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,395 software developers and data experts.

C++ File I/O creating the input file by user help!

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     cout  << fixed  << showpoint;
  9.  
  10.     float a0,a1,a2,a3,a4,a5,a6,a7,a8;   // Nine constant values in the polynomial
  11.     float x;            // Value for x in the polynomial
  12.     float Polynomial;   // Value for the polynomial
  13.     ifstream inData;    // declares input stream
  14.     ofstream outData;   // declares output stream
  15.     string fileName;    // Inputs file name
  16.  
  17.     cout << "This program computes and outputs the result of the polynomial" << endl;
  18.     cout << "The values for a8,a7,a6,a5,a4,a3,a2,a1,a0 and x are read from " << endl;
  19.     cout << "inputfile.dat and the outputs are written to outputfile.dat" << endl;
  20.  
  21.     cout << "Enter the input file name: ";      // Prompt
  22.     cin >> fileName;    // Inputs the file name
  23.     inData.open(fileName.c_str());      // Opens the input file with the name
  24.  
  25.     outData.open("outputfile.dat");
  26.     // binds program variable outData to the output file "outputfile.dat"
  27.  
  28.     // Inputs values of a and x for the polynomial function
  29.     inData  >> a8 >> a7 >> a6 >> a5 >> a4 >> a3 >> a2 >> a1 >> a0 >> x;
  30.  
  31.     // The function of the polynomial and it calculates the result of the function
  32.     Polynomial = (a8*pow(x, 8)) + (a7*pow(x, 7)) + (a6*pow(x, 6)) + (a5*pow(x, 5))
  33.                + (a4*pow(x, 4)) + (a3*pow(x, 3)) + (a2*pow(x, 2)) + (a1*x) + a0;
  34. outData  << Polynomial  << endl; // Prints the result of the polynomial
  35.  
  36.     return 0;
  37. }

this program i made it to ask me to type the name of the inputfile that will be created but it is not created i typed inputfile.dat but it is not there what is wrong with it help!
Feb 27 '07 #1
1 1871
Ganon11
3,652 Expert 2GB
Well, you shouldn't be creating an input file at all - a new input file would be empty, so no data could be given to the program. Make sure inputfile.dat is already made in the same folder as the program, and fill it with the polynomial coefficients and the x value.
Feb 27 '07 #2

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

Similar topics

2
by: @lias | last post by:
Hi all I have a webpage where I want the user to input filenames. To make this easier, I use a file input type so that the user can select files rather than typing in the filename, using the...
1
by: orit | last post by:
I have the following xml file: <?xml version="1.0" encoding="utf-8" ?> <course id="2555" title="Developing Microsoft .NET Applications for Windows (Visual C# .NET)" length="5 days"...
11
by: Nina | last post by:
I have a text file which stores user input. Later if user edited the input data from a input form. How can I update the input text file? If update the text file too often, would it cause...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
6
by: HaggMan | last post by:
I'm creating a page that: - accepts user input in whatever language - saves that input to a file - reads the file and displays the original input The following code successfully writes the user...
4
by: kevin | last post by:
Hi, I am trying to create a page so the user can browse the network, select a file and have that file name (text) inserted into our sql DB so I can build the hyperlink path later on. Here's what...
4
by: sufian | last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message: echo("<div id=\"message\" class=\"success\">Thank you! You...
5
eragon
by: eragon | last post by:
I wrote this function to create a new file when the user posts in my forums, and its not creating a new file, can you help me? this script is not copyrighted as the last one. function...
6
by: portCo | last post by:
Hello there, I am creating a vb application which is some like like a questionare. Application read a text file which contains many questions and display one question and the input is needed...
1
by: aswinikg | last post by:
HI I am a newbie to 'C' and embedded application . I have a code in which the input parameter is being assigned in two ways (i) Runtime through user (ii)...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.