473,799 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

6 New Member
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 1891
Ganon11
3,652 Recognized Expert Specialist
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
44027
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 HTML below. <input type="file" size="25" maxlength="256" id="filename" onchange="AddFile()" /> The problem I have is that the javascript function AddFile() is only run under
1
2938
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" source="http://www.microsoft.com/learning/syllabi/en-us/2555Afinal.mspx"> <module id="1" title="Introducing Windows Forms" location="D:\Disk-C\Documents and Settings\orit_itzhar.ATRICA\My Documents\XML\csharp"> <lesson id="1.1"> <subject>Creating a...
11
2144
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 problem? Thanks in advance for any help.
5
3793
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 List<RoleData> GetRoles() { return GetRoles(null, false); }
6
20044
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 input to a file (when I open the file, it's in the correct font), but I can't get PHP to read the file and display the correct characters. HTML --------------- Form
4
4022
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 seems to be the problem. These are video files and are enormous with long crazy names so trying to hand type the file name in a text box is not an option. So I'm using an Input "file" control so when the user browses out onto the network...
4
4667
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 have been successfully registered.</div>"); within 1.5 seconds. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
5
3564
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 createNewFile($name,$mail,$subject,$comments,$count,$date,$other="",$up="0") { global $settings; $header=implode('',file('header.txt')); $footer=implode('',file('footer.txt')); $content=' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
6
2491
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 from user to calculate the score. Here is a problem. I can read a text file. However, it's read whole file at a time. So,
1
4229
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) parameter tile the problem is, i can't give the runtime input as am a in need of creating a standalone product without user interaction. the parameters in the parameter file is assigned as the input by "FILE" pointer concepts ...
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9079
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.