tallygal 0 Light Poster

Disregard, I figured it out! Thanks.

' Printing a paycheck.
Imports System.Drawing.Printing
Imports System.Drawing.Imaging

Public Class CheckWriter
   ' PrintPage event raised for each page to be printed
    Private graphicsObject As Graphics
    Private imageValue As Image

    ' display the wood preview
    Private Sub woodRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles woodRadioButton.CheckedChanged
        PictureBox1.Image = My.Resources.wood

    End Sub

    ' display the brick preview
    Private Sub brickRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles brickRadioButton.CheckedChanged
        PictureBox1.Image = My.Resources.bricks
    End Sub

    Private Sub printDocument_PrintPage(ByVal sender As System.Object,
      ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
      Handles printDocument.PrintPage

        Dim fontObject As Font ' variable to store the font

        ' store a control's x- and y-coordinates
        Dim yPosition As Integer
        Dim xPosition As Integer

        ' represent the left margin of the page
        Dim leftMargin As Integer = e.MarginBounds.Left

        ' represent the top margin of the page
        Dim topMargin As Integer = e.MarginBounds.Top

        ' store a control's text
        Dim controlText As String = Nothing

        e.Graphics.DrawImage(PictureBox1.Image, leftMargin, topMargin, Me.Width, Me.Height - 60)

        ' iterate over the controls on the Form,
        ' printing the text displayed in each control
        For Each controlObject In Me.Controls
            ' do not print Buttons
            If Not (TypeOf controlObject Is Button) Then
                controlText = controlObject.Text

                Select Case controlObject.Name
                    Case "dateTimePicker" ' underline the date
                        fontObject = New Font("Segoe UI", 9.0F,
                           FontStyle.Underline)
                    Case "amountTextBox" ' draw a box around the amount
                        e.Graphics.DrawRectangle(Pens.Black,
                           amountTextBox.Location.X + leftMargin,
                           amountTextBox.Location.Y + topMargin - 2,
                           amountTextBox.Width, amountTextBox.Height)
                        fontObject = controlObject.Font ' default font
                    Case Else
                        fontObject = controlObject.Font ' default font
                End Select

                ' set the …
tallygal 0 Light Poster

I'm trying to print the selection of my picturebox as the background of the image. I can get the image to show, but it's not the height and width of the background. Any help would be appreciated. Thank you.

' Fig. 15.24: CheckWriter.vb
    ' Printing a paycheck.
    Imports System.Drawing.Printing
    Imports System.Drawing.Imaging

    Public Class CheckWriter
       ' PrintPage event raised for each page to be printed
        Private graphicsObject As Graphics
        Private imageValue As Image

        ' display the wood preview
        Private Sub woodRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles woodRadioButton.CheckedChanged
            PictureBox1.Image = My.Resources.wood

        End Sub

        ' display the brick preview
        Private Sub brickRadioButton_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles brickRadioButton.CheckedChanged
            PictureBox1.Image = My.Resources.bricks
        End Sub

        Private Sub printDocument_PrintPage(ByVal sender As System.Object,
          ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
          Handles printDocument.PrintPage

            Dim fontObject As Font ' variable to store the font

            ' store a control's x- and y-coordinates
            Dim yPosition As Integer
            Dim xPosition As Integer

            ' represent the left margin of the page
            Dim leftMargin As Integer = e.MarginBounds.Left

            ' represent the top margin of the page
            Dim topMargin As Integer = e.MarginBounds.Top

            ' store a control's text
            Dim controlText As String = Nothing

            e.Graphics.DrawImage(PictureBox1.Image, Me.Width, Me.Height)

            ' iterate over the controls on the Form,
            ' printing the text displayed in each control
            For Each controlObject In Me.Controls
                ' do not print Buttons
                If Not (TypeOf controlObject Is Button) Then
                    controlText = controlObject.Text

                    Select Case controlObject.Name
                        Case "dateTimePicker" ' underline the date
                            fontObject = New Font("Segoe UI", 9.0F,
                               FontStyle.Underline)
                        Case "amountTextBox" ' draw a box …
tallygal 0 Light Poster

That worked perfectly. Thank you so much!

tallygal 0 Light Poster

I'm trying to write a function that that returns an table from an array. But, for some reason, it is only displaying the first row or the array instead of all.

<html>
<link rel="stylesheet" type="text/css" href="week13.css" />
</head>
<body>
<h2>table</h2>
<br>
<br>
<?php
$table = array("440" => "cubic inch engine","truck F" => 150);
echo ("<table border='1'>\n");
function t6($table)
{
        foreach ($table as $key => $value)
        return ("<tr><td>$key</td><td>$value</td></tr>\n");
}
echo t6($table);
echo "</table>";
?>
<br>
</body>
</html>
tallygal 0 Light Poster

I appreciate the criticsm, it is how we learn to do it right. I appreciate your help. I got it working. This is the code. I hope it's not to ugly!

'Ex. 6.10 Sales Commission
Public Class SalesCommission

    'stores total of sales person earnings

    Dim commPercentage As Integer


    'calculate and display number of items sold
    Public Sub calculateButton_Click(ByVal sender As System.Object,
            ByVal e As System.EventArgs) Handles calculateButton.Click

        'get number of items
        Dim itemsSold As Integer = Convert.ToInt16(Val(ItemsSoldTextBox.Text))
        Dim commItems As Integer = Convert.ToInt16(Val(ItemsSoldTextBox.Text))

        Select Case commItems
            Case 0 To 50
                commPercentage = 6
            Case 51 To 100
                commPercentage = 7
            Case 101 To 150
                commPercentage = 8
            Case Is >= 151
                commPercentage = 9

        End Select


        'Obtain gross sales
        Dim grossSales As Decimal = CalculateItems(itemsSold)
        Dim commTotal As Decimal = CommissionTotal(commItems)

        ' display gross sales
        grossOutputLabel.Text = String.Format("{0:C}", grossSales)

        ' display total commission
        salesOutputLabel.Text = String.Format("{0:C}", commTotal)

        ' display commission percentage
        commOutputLabel.Text = String.Format(commPercentage & "%")

    End Sub

    ' calculates gross sales
    Function CalculateItems(ByVal itemTotal As Decimal) As Decimal
        Const COST As Decimal = 10
        Return itemTotal * COST
    End Function

    ' Commission Percentage
    Function CommissionTotal(ByVal commAmount As Integer) As Integer
        Return commPercentage
    End Function

    Function CommissionTotal(ByVal grossSales As Decimal, ByVal commPercentage As Integer) As Decimal
        Return (commpercentage * grossSales) / 100

    End Function

    'clear text boxes
    Private Sub itemsSoldTextBox_TextChanged(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles ItemsSoldTextBox.TextChanged

        grossOutputLabel.Text = String.Empty
        commOutputLabel.Text = String.Empty
        salesOutputLabel.Text = String.Empty
    End Sub

End Class
tallygal 0 Light Poster

I'm creating a sales commission application. I have to use a Select....Case statement to implement the sales commission schedule. When the calculate button is clicked, three methods should be called. One to calculate gross sales, one to calcuate the commission percentage based on the commission schedule and one to calculate the sale's persons earnings. When i press the calculate button, my gross sales display, but the sales persons commission percentage and the sales persons earnings just display as zero....

Public Class SalesCommission

    'stores total of sales person earnings
    Dim salesEarnings As Decimal
    Dim commTotal As Decimal
    Dim items As Integer

    Private Property grossSales As Integer

    Private Property commpercentage As String

    'calculate and display number of items sold
    Public Sub calculateButton_Click(ByVal sender As System.Object,
            ByVal e As System.EventArgs) Handles calculateButton.Click

        'get number of items
        items = Convert.ToInt16(Val(ItemsSoldTextBox.Text))

        'Obtain gross sales
        Dim grossSales As Decimal = CalculateItems()
        Dim commTotal As Decimal = CommissionTotal()
        Dim commPercentage As Decimal = commPerc()

        ' display gross sales
        grossOutputLabel.Text = String.Format("{0:C}", grossSales)

        ' display total commission
        salesOutputLabel.Text = String.Format("{0:C}", commTotal)

        ' display commission percentage
        commOutputLabel.Text = String.Format(commPercentage & "%")

    End Sub

    ' calculates gross sales
    Function CalculateItems() As String
        grossSales = items * 10
        Return grossSales
    End Function

    ' Commission Percentage
    Function commPerc() As String

        Select Case commpercentage
            Case 0 To 50
                commpercentage = 6
            Case 51 To 100
                commpercentage = 7
            Case 101 To 150
                commpercentage = 8
            Case Is >= 151
                commpercentage = 9
        End Select

        Return commpercentage

    End Function

    Function CommissionTotal() As String …
tallygal 0 Light Poster

I got it working. As soon as I assigned my Grades Integer a value, it worked. Thank you so much!

tallygal 0 Light Poster

Ok, I have it reading in the file now, but the grades all display as 0 instead of what's in the file.

' Exercise 8.2: EnhancedClassAverage.vb
Imports System.IO ' using classes from this namespace

Public Class EnhancedClassAverage
    Dim fileWriter As StreamWriter ' writes data to a text file
    Dim FileName As String ' name of file to save data
    Enum GradesFiles
        Grades
    End Enum

    ' opens a file in which grades are stored
    Private Sub NewToolMenuStripItem_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click

        CloseFile() 'ensure that any prior file is closed
        Dim result As DialogResult ' stores reslt of Save dialog

        Using fileChooser As New SaveFileDialog()
            result = fileChooser.ShowDialog()
            FileName = fileChooser.FileName ' get specified file name
        End Using

        If result <> Windows.Forms.DialogResult.Cancel Then
            Try
                ' open or create file for writing
                fileWriter = New StreamWriter(FileName, True)

                ' enable controls
                CloseToolStripMenuItem.Enabled = True
                submitGradeButton.Enabled = True
                gradeTextBox.Enabled = True
            Catch ex As IOException
                MessageBox.Show("Error Opening File", "Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub submitGradeButton_Click(ByVal sender As System.Object,
         ByVal e As System.EventArgs) Handles submitGradeButton.Click

        ' if the user entered a grade
        If gradeTextBox.Text <> String.Empty Then
            Try
                Dim grade As Integer =
                    Convert.ToInt32(gradeTextBox.Text)

                ' add the grade to the end of the gradesListBox
                gradesListBox.Items.Add(gradeTextBox.Text)
                fileWriter.WriteLine(gradeTextBox.Text)
                gradeTextBox.Clear() ' clear the gradeTextBox

            Catch ex As IOException
                MessageBox.Show("Error Writing to File", "Error",
                   MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If

        gradeTextBox.Focus() ' gives the focus to the gradeTextBox
    End Sub

    Private Sub calculateAverageButton_Click(ByVal sender As System.Object,
       ByVal e As …
tallygal 0 Light Poster

Here is what I have to do.

this code needs to be modified to be able to enable the user to select a file in which to store grades. The application should allow the user to write any number of grades into that file and it should write one grade per line. Then it has to be modified to allow the user to specify the location and name of the file containing grades. The application should read the grades from the file, then display the total of grades and the class average.

I have it writing to the file fine, but I can't get it to read from a file.

Imports System.IO ' using classes from this namespace

Public Class EnhancedClassAverage
    Dim fileWriter As StreamWriter ' writes data to a text file
    Dim FileName As String ' name of file to save data

    ' opens a file in which grades are stored
    Private Sub NewToolMenuStripItem_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click

        CloseFile() 'ensure that any prior file is closed
        Dim result As DialogResult ' stores reslt of Save dialog

        Using fileChooser As New SaveFileDialog()
            result = fileChooser.ShowDialog()
            FileName = fileChooser.FileName ' get specified file name
        End Using

        If result <> Windows.Forms.DialogResult.Cancel Then
            Try
                ' open or create file for writing
                fileWriter = New StreamWriter(FileName, True)

                ' enable controls
                CloseToolStripMenuItem.Enabled = True
                submitGradeButton.Enabled = True
                gradeTextBox.Enabled = True
            Catch ex As IOException
                MessageBox.Show("Error Opening File", "Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private …
tallygal 0 Light Poster

I have to create a cafeteria survey application. Twenty students were asked to reate, on a scale of 1 to 10, the quality of the food in the student cafeteria, with 1 being "awful" and 10 being "excellent." Allow the user input to be entered using a ComboBox. Use an integer array to store the frequency of each rating. Display the frequencies as a bar chart in a list box.

I can get the comboBox and everthing, but it's not displaying the bar chart. Any help would be appreciated. Here is my code.

Public Class Form1

    'String array stores ratings
    Dim ratings() As String = {"1-Awful", "2", "3", "4", "5", "6", "7", "8", "9", "10-Excellent"}
    Dim studentCount As Integer 'number of student ratings entered
    Dim frequency(9) As Integer

    Private Sub CafeteriaSurvey_Load(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles MyBase.Load
        studentCount = 0
        studentRatingComboBox.DataSource = ratings
        DisplayBarChart()
    End Sub

    Private Sub submitButton_Click(ByVal sender As Object,
        ByVal e As System.EventArgs) Handles submitButton.Click

        Dim count As Integer = Val(studentRatingComboBox.Text)
        studentCount += 1
    End Sub

    Sub DisplayBarChart()

        'display the output header
        barChartListBox.Items.Add(
            "Rating" & vbTab & "Frequency")
        For count = 0 To frequency.GetUpperBound(0)
            Dim bar As String

            If count = 0 Then
                bar = String.Format("{0, 0}", 1)
            Else
                bar = String.Format("{0,0}", count + 1)
            End If

            For stars = 1 To frequency(count)
                bar &= ("*")
            Next

            barChartListBox.Items.Add(bar)
        Next count
    End Sub
End Class
tallygal 0 Light Poster

The program is outputting

Enter a number in inches: 53
1346 mm
OR
1 m 2 cm and 0 mm


It should output:

1346 mm
OR
1 m 34 cm and 6 mm


Something is going wrong in the math after it converts from the inches to M.

tallygal 0 Light Poster

The question is:
Write a code that will take and inches input and convert it to mm. Then display the same result using m, cm, and mm. Example would be:

Input:

53 inches

Output:

1346 mm
OR
1 m 34 cm and 6 mm


Something is happening with the remainder conversion that is not calculating the cm and mm right. I know I should probably using casting, but I'm not sure how to. Can someone help?

Thank you.

import java.util.Scanner;
import java.text.DecimalFormat;

public class Format
{
	public static void main (String[] args)
	{
		Scanner scan = new Scanner (System.in);
		
		System.out.print ("Enter a number in inches: ");
		double inches = scan.nextInt();
		
		double firstmm = inches * 25.4;
			
		
		double m = inches * 0.0254;
			inches = inches % 0.0254;
			
		double cm = inches * 100;
			inches = inches % 100;
			
		double mm = inches * 10;
			inches = inches % 10;
				 
			
		DecimalFormat fmt = new DecimalFormat ("0");
		
		System.out.println (fmt.format(firstmm) + "  mm");
		System.out.println ("OR");
		System.out.print(fmt.format (m) + " m ");
		System.out.print(fmt.format (cm) + " cm and ");
		System.out.print(fmt.format (mm) + " mm");
		}
}
tallygal 0 Light Poster

Thanks.

tallygal 0 Light Poster

That is all she gave us. That is the exact question, word for word.

tallygal 0 Light Poster

Can someone tell me if this is write?


Rewrite the following if/else/if structure as nested if elses.

if (status == ‘P’ && amount >= 10000)
	due_flag = true;
else if (status == ‘P’)
	time_remaining - = 1;
else if (status == ‘O’)
{
	time_remaining = 0;
	warning_flag = true;
}

This is what I have:

if (status == 'P' && amount >= 10000)
   {
              due_flag = true;
   }
   {
             if (status == 'P')
             {
                  time_remaining - = 1;
             }
             else (status == 'O')
             {
                  time_remaining = 0;
                  warning_flag = true;
             }

   }
tallygal 0 Light Poster

I understand why i'm getting garbage, its not reading from the input file. Can someone help me to understand how to get it to read from my input file. I realized all i've done is opened it.

Completely changed what i was doing again. I've decided to us a
2d array to sum the totals that I need and eventually average them out. But, I'm not sure why, but my output is just increments of ten.

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{

    const int NUM_STUDENTS = 40;           //Number of Students
    const int NUM_SCORES = 4;               //Number of Scores
    double scores[NUM_STUDENTS][NUM_SCORES];
    double total;                           //Accumulator
    double average;                         //Hold Average
    
    fstream students;
    
    students.open("C:\\grades.txt");
    
   
    
    
    for (int row = 0; row < NUM_STUDENTS; row++)
    {
        total = 0;
        
        for (int col = 4; col < NUM_SCORES; col++)
        total += scores[row][col];
        cout << (row + 1) << total << endl;
        
        //average = total/NUM_SCORES;
        
        //cout << "Scores average for student "
        //   << (row +1) << " is " << average << endl;
    }
    
    students.close ();    
    
    


    system("PAUSE");
    return EXIT_SUCCESS;
}
tallygal 0 Light Poster

Completely changed what i was doing again. I've decided to us a
2d array to sum the totals that I need and eventually average them out. But, I'm not sure why, but my output is just increments of ten.

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{

    const int NUM_STUDENTS = 40;           //Number of Students
    const int NUM_SCORES = 4;               //Number of Scores
    double scores[NUM_STUDENTS][NUM_SCORES];
    double total;                           //Accumulator
    double average;                         //Hold Average
    
    fstream students;
    
    students.open("C:\\grades.txt");
    
   
    
    
    for (int row = 0; row < NUM_STUDENTS; row++)
    {
        total = 0;
        
        for (int col = 4; col < NUM_SCORES; col++)
        total += scores[row][col];
        cout << (row + 1) << total << endl;
        
        //average = total/NUM_SCORES;
        
        //cout << "Scores average for student "
        //   << (row +1) << " is " << average << endl;
    }
    
    students.close ();    
    
    


    system("PAUSE");
    return EXIT_SUCCESS;
}
tallygal 0 Light Poster

Thank you for the help. I really do appreaciate it. I've got it displaying exactly what I want, but I have a line of garbage above the output I want. Can you tell were it's coming from?

#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;

int main()
{
    const int SIZE = 15; //Length of line
    char first[SIZE], last[SIZE];    
    const int ARRAY_SIZE = 100;
    int numbers[ARRAY_SIZE], t1, t2, a1, a2, a3, a4, attendance;
    int count;
    
    ifstream students;
    
    students.open("C:\\grades.txt");

    count = 0;
    
    do
   	{
    cout << first << " " << last << " " << a1 << " " << a2 << " " << a3 << " " << a4 << " " << endl ;
    cout << " " << endl;
    cout <<"" << endl;
    }
    
    while
    (
      count < ARRAY_SIZE &&
      students  >> first >> last >> t1 >> t2 >> a1 >> a2 >> a3 >> a4 >> attendance
    );
    {
      count++;
    }
    
    students.close ();
    
  
    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

The output looks like this:

tallygal 0 Light Poster

If i delete the ;, it reads the first number and the rest is gibberish.

tallygal 0 Light Poster

this is what I got so far. I can get it to read the first number that i want it to, but not the rest.

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    const int SIZE = 15; //Length of line
    char first[SIZE], last[SIZE];    
    const int ARRAY_SIZE = 4;
    int numbers[ARRAY_SIZE], t1, t2, attendance;
    int count;
    
    ifstream students;
    
    students.open("C:\\grades.txt");
    
    for (count = 0; count < ARRAY_SIZE; count++);
    students >> first >> last >> t1 >> t2 >> numbers[count] >> attendance;
    
    students.close ();
    
   	for (count = 0; count < ARRAY_SIZE; count++);
    cout << numbers[count] << " " ;
    cout <<"" << endl;
    
    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
tallygal 0 Light Poster

I have to utilize an array for a homework project. I want it to read a line from a file on my hard drive. However, the line starts with words and ends with numbers. I only need to utilize the numbers for a function that I want to pass a value from. I'm sorry if this doesn't make sense. Every example that i've seen for reading from a file into an array is for int and not any type of char, let alone both. Can someone point me in the right direction.

This is what the text file looks like:

Barney Jones 95 83 92 85 87 85 29
Sandra King 99 97 92 91 92 95 32
Josh Harding 0 0 0 0 31 37 30

tallygal 0 Light Poster

I finally got it working. It is writing to the output file as needed. It's not the cleanest I could have done it, but it works.

Thanks for all of your help.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <sstream>

using namespace std;

//Function Prototypes
void accept (char letter);
void transfer (char letter);
void decline (char letter);
int menu ();
 
int main()
{
        
    
    const int SIZE = 100; //Length of line
    char first[SIZE], last[SIZE], phone[SIZE], status, address[SIZE];
    int X, pref, tamount;


    ifstream inputFile; //File Stream Object
    inputFile.open ("c:\\potentials.txt", ios::in);  //Open File
    
   
    if (inputFile.fail()) //Error Opening File
   { 
      cout << "Error opening file. The file could not be found.\n";
      cout <<""<<endl;
      system ("PAUSE");
      return EXIT_FAILURE;  
   }
   
    ofstream outputFile;  //File to output to
    outputFile.open ("c:\\confirmed.txt", ios::app);
    
    if (outputFile.fail()) //Error Opening File
   { 
     cout << "Error opening file. The file could not be found.\n";
     cout <<""<<endl;
     system ("PAUSE");
     return EXIT_FAILURE;  
   }

  
   
  do
    {
    system ("CLS");        
    cout << "Customer Call list:" << endl;
    cout << " " << endl;
    
    // Determine status
    inputFile >> status;
    if (status == 'X' || status == 'x')
   {
      cout << "Preferred Customer offer a 7.9% interest rate!" << endl;
      pref=0;
   }  
    else 
   {
      cout << "Offer a 12.9% interest rate!" << endl; 
      pref=1;
   }  
    
    // Get name
    inputFile >> first >> last;
    cout << first << " " << last << endl;    
    
    // Get phone number
    inputFile >> phone;
    cout << phone << endl;
    cout << "" << endl;
    cout << "" << endl; …
tallygal 0 Light Poster

The main requirements are that we have three functions other than main and don't use globals variables. We have to input from one file and output to another. I was thinking that re-opening was messing it up. I really might have to rethink all of my functions.

Thank you for your help. It really is appreciated.

tallygal 0 Light Poster

I actually thought about making it a whole separate function. I might just do that. But I'm having issues in the void accept function and the transfer function. They both do the same thing.

tallygal 0 Light Poster

So I've decided to just force my output to file within each function since I can't get my functions working right. However, my problem is when I output the address to file, it cuts off the first half of the address line. I've tried using cin.getline and std::getline and they both do the same thing. Any ideas?

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <sstream>

using namespace std;

//Function Prototypes
void accept (char letter);
void transfer (char letter);
void decline (char letter);
int menu ();
 
int main()
{
        
    
    const int SIZE = 100; //Length of line
    char first[SIZE], last[SIZE], phone[SIZE], status, address[SIZE];
    int X, pref, tamount;


    ifstream inputFile; //File Stream Object
    inputFile.open ("c:\\potentials.txt", ios::in);  //Open File
    
   
    if (inputFile.fail()) //Error Opening File
   { 
      cout << "Error opening file. The file could not be found.\n";
      cout <<""<<endl;
      system ("PAUSE");
      return EXIT_FAILURE;  
   }
   
    ofstream outputFile;  //File to output to
    outputFile.open ("c:\\confirmed.txt", ios::out);
    
    if (outputFile.fail()) //Error Opening File
   { 
     cout << "Error opening file. The file could not be found.\n";
     cout <<""<<endl;
     system ("PAUSE");
     return EXIT_FAILURE;  
   }

  
   
  do
    {
    system ("CLS");        
    cout << "Customer Call list:" << endl;
    cout << " " << endl;
    
    // Determine status
    inputFile >> status;
    if (status == 'X' || status == 'x')
   {
      cout << "Preferred Customer offer a 7.9% interest rate!" << endl;
      pref=0;
   }  
    else 
   {
      cout << "Offer a 12.9% interest rate!" << endl; 
      pref=1;
   }  
    
    // Get name
    inputFile >> first >> last;
    cout << first << " " << last …
tallygal 0 Light Poster

We're doing them right now. She said that we don't have to pass information in this particular assignment but that it was good practice.

tallygal 0 Light Poster

You're right, I don't completely understand how they work. I'm taking and online beginning C++ class and trying to learn this on my own. Thank you for the links.

tallygal 0 Light Poster

I decided to try and start fresh. I don't know if I'm headed in the right direction or not but everything is working except that my values still aren't returning to the switch statement so I can output them into my file.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;

//Function Prototypes
char accept ();
char transfer ();
void decline ();
char menu ();
 
int main()
{
        
    
    const int SIZE = 100; //Length of line
    char first[SIZE], last[SIZE], phone[SIZE], status, address[SIZE];
    int X, pref, tamount;


    ifstream inputFile; //File Stream Object
    inputFile.open ("c:\\potentials.txt", ios::in);  //Open File
    
   
    if (inputFile.fail()) //Error Opening File
   { 
      cout << "Error opening file. The file could not be found.\n";
      cout <<""<<endl;
      system ("PAUSE");
      return EXIT_FAILURE;  
   }
   
    ofstream outputFile;  //File to output to
    outputFile.open ("c:\\confirmed.txt", ios::app);
    
    if (outputFile.fail()) //Error Opening File
   { 
     cout << "Error opening file. The file could not be found.\n";
     cout <<""<<endl;
     system ("PAUSE");
     return EXIT_FAILURE;  
   }

  
   
  do
    {
    system ("CLS");        
    cout << "Customer Call list:" << endl;
    cout << " " << endl;
    
    // Determine status
    inputFile >> status;
    if (status == 'X' || status == 'x')
   {
      cout << "Preferred Customer offer a 7.9% interest rate!" << endl;
      pref=0;
   }  
    else 
   {
      cout << "Offer a 12.9% interest rate!" << endl; 
      pref=1;
   }  
    
    // Get name
    inputFile >> first >> last;
    cout << first << " " << last << endl;    
    
    // Get phone number
    inputFile >> phone;
    cout << phone << endl;
    cout << "" << endl;
    cout …
tallygal 0 Light Poster

The tamount is input by the user in the transfer function.

tallygal 0 Light Poster

We are doing an assignment that reads from a file on the hard drive, asks for user input and then writes it to a different file on the hard drive. We have to use three different functions, besides the main, and cannot use global variables.

I cannot seem to get all of the information I need to print to my output file. Everything prints in the file except the address and tamount. The tamount prints, just not what is input by the user.

Thanks in advance for your help.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;

//Function Prototypes
void accept (char letter);
void transfer (char letter);
void decline (char letter);
int menu ();

int main()
{
        
    
    const int SIZE = 100; //Length of line
    char first[SIZE], last[SIZE], phone[SIZE], status, address[SIZE];
    int X, pref, tamount;
    
    ifstream inputFile; //File Stream Object
    inputFile.open ("c:\\potentials.txt", ios::in);  //Open File
    
   
    if (inputFile.fail()) //Error Opening File
   { 
      cout << "Error opening file. The file could not be found.\n";
      cout <<""<<endl;
      system ("PAUSE");
      return EXIT_FAILURE;  
   }
   
    ofstream outputFile;  //File to output to
    outputFile.open ("c:\\confirmed.txt", ios::out);
    
    if (outputFile.fail()) //Error Opening File
   { 
     cout << "Error opening file. The file could not be found.\n";
     cout <<""<<endl;
     system ("PAUSE");
     return EXIT_FAILURE;  
   }

  do
    {
    system ("CLS");        
    cout << "Customer Call list:" << endl;
    cout << " " << endl;
    
    // Determine status
    inputFile >> status;
    if (status == 'X' || status == 'x')
   {
      cout << "Preferred Customer offer a 7.9% interest rate!" << …
tallygal 0 Light Poster

Thanks, I got it working.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;

//Function Prototypes
void accept (char letter);
void transfer (char letter);
void decline (char letter);
int menu ();

int main()
{
        
    
    const int SIZE = 100; //Length of line
    char first[SIZE], last[SIZE], phone[SIZE], status, address[SIZE];
    int X, pref, tamount;
    
    ifstream inputFile; //File Stream Object
    inputFile.open ("c:\\potentials.txt", ios::in);  //Open File
    
   
    if (inputFile.fail()) //Error Opening File
   { 
      cout << "Error opening file. The file could not be found.\n";
      cout <<""<<endl;
      system ("PAUSE");
      return EXIT_FAILURE;  
   }
   
    ofstream outputFile;  //File to output to
    outputFile.open ("c:\\confirmed.txt", ios::out);
    
    if (outputFile.fail()) //Error Opening File
   { 
     cout << "Error opening file. The file could not be found.\n";
     cout <<""<<endl;
     system ("PAUSE");
     return EXIT_FAILURE;  
   }

  do
    {
    system ("CLS");        
    cout << "Customer Call list:" << endl;
    cout << " " << endl;
    
    // Determine status
    inputFile >> status;
    if (status == 'X' || status == 'x')
   {
      cout << "Preferred Customer offer a 7.9% interest rate!" << endl;
      pref=0;
   }  
    else 
   {
      cout << "Offer a 12.9% interest rate!" << endl; 
      pref=1;
   }  
    
    // Get name
    inputFile >> first >> last;
    cout << first << " " << last << endl;    
    
    // Get phone number
    inputFile >> phone;
    cout << phone << endl;
    cout << "" << endl;
    cout << "" << endl;
    cout << "" << endl;

   char letter;
   
    
        letter = menu ();
        switch (letter)
        {
            case 'A':  accept ('A');
                       cin.getline (address, SIZE);
                       outputFile << first << " " << last << …
tallygal 0 Light Poster

I am inputing from a text file, displaying it on the screen, displaying the menus and the choosing from there. It will repeat the menu, but, how to do I get it to read the next line in my input file and display it to the screen before repeating the menu?

Here's what I have.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;

//Function Prototypes
void accept (char letter);
void transfer (char letter);
void decline (char letter);
int menu ();

int main()
{
        
    
    const int SIZE = 100; //Length of line
    char first[SIZE], last[SIZE], phone[SIZE], status;
    int X, pref;
    
    ifstream inputFile; //File Stream Object
    inputFile.open ("c:\\potentials.txt", ios::in);  //Open File
    
   
    if (inputFile.fail()) //Error Opening File
   { 
      cout << "Error opening file. The file could not be found.\n";
      cout <<""<<endl;
      system ("PAUSE");
      return EXIT_FAILURE;  
   }

    // Determine status
    inputFile >> status;
    if (status == 'X' || status == 'x')
   {
      cout << "Preferred -- 7.9%" << endl;
      pref=0;
   }  
    else 
   {
      cout << "12.9%" << endl; 
      pref=1;
   }
    
    // Get name
    inputFile >> first >> last;
    cout << first << " " << last << endl;    
    
    // Get phone number
    inputFile >> phone;
    cout << phone << endl;
    cout << "" << endl;

   char letter;
    
    do
    {
        letter = menu ();
        switch (letter)
        {
            case 'A':  accept ('A');
                       break; 
            case 'a':  accept ('a');
                       break;
            case 'T':  transfer ('T');
                       break;
            case 't':  transfer ('t');
                       break;
            case 'D':  decline ('D');
                       break;
            case 'd':  decline ('d');
                       break;
        }
    }   while …
tallygal 0 Light Poster

Thanks everyone, I figured a way around it.

tallygal 0 Light Poster

Can you all tell me if i'm even on the right track with this program. I'm really starting to doubt it. I've gotten the switch statements to read the letter and access the right menu, but I also need it to read information from a file on the hard drive. Here are the instructions for the program and what I have so far.

Instructions:
Background

Your assignment this time is to build an interactive program that allows telemarketers to solicit people in a file for credit cards. The program will open up a text file on the C drive filled with potential customers and display processed data to the screen in a way that the telemarketer can use it. The program will then give them choices to continue the sales call and finally, will save output to a file on the C drive for future credit card processing.


Functionality

The program should do the following:


• Read a customer status, name and phone number from a file called C://potentials.txt

o A customer has a preferred status if the field contains an ‘X’. If it contains anything else, they are not preferred.

• Display the name, phone number and the available interest rate for that customer so that the telemarketer can read it, call the customer and offer them a credit card

o Preferred customers get 7.9%, everybody else gets 12.9%

• Display a menu offering the …

tallygal 0 Light Poster

Mit --

You're right...it's not passing information. The status and letter come back blank. Let me see what I can figure out on passing information between my functions.

tallygal 0 Light Poster

I'm using Bloodshed DEV-C++.

This is my first programming class. I was doing well until we got to loops, but I think I'm starting to pick them up.

tallygal 0 Light Poster

Thanks... I changed it to this, but it still is not reading the if statements

char selection;
    
    do
    {
        selection = menu ();
        switch (selection)
        {
            case 'A':  accept ();
                       break; 
            case 'a':  accept ();
                       break;
            case 'T':  transfer ();
                       break;
            case 't':  transfer ();
                       break;
            case 'D':  decline ();
                       break;
            case 'd':  decline ();
                       break;
        }
    }   while (1);
    return 0;    
}
tallygal 0 Light Poster

This program compiles and lets me select a letter from the menu, but then it just repeats the menu, it never outputs the statements that correspond with the letter chosen. Any ideas why?

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;

//Function Prototypes
void accept ();
void transfer ();
void decline ();
int menu ();

int main()
{
        
    
    const int SIZE = 100; //Length of line
    char first[SIZE], last[SIZE], phone[SIZE], status;
    int X;
       
    ifstream inputFile; 
    inputFile.open ("c:\\potentials.txt", ios::in);
    
   
    if (inputFile.fail()) 
   { 
      cout << "Error opening file. The file could not be found.\n";
      cout <<""<<endl;
      system ("PAUSE");
      return EXIT_FAILURE;  
   }

    // Determine status
    inputFile >> status;
    if (status == 'X' || status == 'x')
   {
      cout << "Preferred -- 7.9%" << endl;
   }  
    else if (!(status == 'X' || status == 'x'))
   {
      cout << "12.9%" << endl; 
   }
    
    // Get name
    inputFile >> first >> last;
    cout << first << " " << last << endl;    
    
    // Get phone number
    inputFile >> phone;
    cout << phone << endl;
    cout << "" << endl;

   char selection;
    
    do
    {
        selection = menu ();
        switch (selection)
        {
            case 1:  accept ();
                     break;
            case 2:  transfer ();
                     break;
            case 3:  decline ();
                     break;
        }
    }   while (1);
    return 0;    
}

//******************************************************************************
// Definition of function menu.                                                *
// Displays the menu and asks user to select an option.                        *
//******************************************************************************

int menu ()
{
    char letter;
    
    cout << "Please press the corresponding letter for the option you would like:" << …