Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1075689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:18:32+00:00 2026-05-16T21:18:32+00:00

Just started learning c++ today and im pretty boggled. its an amazing language but

  • 0

Just started learning c++ today and im pretty boggled. its an amazing language but im having some trouble overwriting a file

#include <iostream>
#include <fstream>

using namespace std;

int main( )
{
    double payIncrease = 7.6;
    double annual;


    double annualIncrease;
    double newAnnual;

    double monthlyIncrease;
    double newMonthly;

    ifstream inStream;
    ofstream outStream;

// heres where the problem lies

        inStream.open("annualSalary.txt" );
        outStream.open("newAnnualSalary.txt");

if i change newAnnualSalary.txt to annualSalary.txt i get some very weird numbers.
does anyone know why?

    inStream >> annual;
    inStream.close();
    double monthly = (annual/12);

    annualIncrease = ((annual/100)*payIncrease);

    monthlyIncrease = ((monthly/100)*payIncrease);


    newMonthly = (monthly + monthlyIncrease);
    newAnnual = (annual + annualIncrease);




    outStream <<"annual salary was: "<<  annual << "\n" ;  
    outStream <<"new annual salary is " << newAnnual << "\n ";
    outStream <<"new monthly salary is " << newMonthly <<"\n ";



    outStream.close();
    return 0;

}

im aware this is a very low skill level question but i am just learning.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:18:33+00:00Added an answer on May 16, 2026 at 9:18 pm

    You can’t open the same file as an istream and an ostream at the same time. Since you are closing the istream pretty early on, why not just put the ostream open call after the istream close? Alternatively you can use an fstream which will allow reads and writes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning C++ (coming from Java ) and am having some serious
I just started learning Java and I'm having trouble formatting string. In the problem
I just started learning JS the other day and am (of course) having some
I just started learning HTML5, I started with normal text file and changed its
I just started learning how to use SwiftMailer and I am having trouble sending
I just started learning C but I don't understand this part of the code.
I´ve just started learning GWT and I´m trying to implement http://gwt.google.com/samples/Showcase/Showcase.html#!CwFileUpload and but failing
I've just started learning Python today. I've been reading a Byte of Python. Right
I've just started learning how to use git today, progressing well. As an experiment,
Just started learning PySide and is having problem with QTimer I have this #!/usr/bin/python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.