Code not working as expected

+3 Pavel Andrei · October 9, 2016
So,i recently watched Bucky's 66th tutorial and whenever i run the code that i made which is exactly like his,it's not working as it should be.I enter an ID(int),name(string) and money(double) and after that i press enter and it should allow me to enter another ID,name and money if i want to or quit,like Bucky's code did,but mine just ends.Why ?I really don't understand.My code is EXACTLY like his.
Please help

Post a Reply

Replies

Oldest  Newest  Rating
+1 Arch38 ツ · October 11, 2016
Cant really help you without seeing your code, :P
0 Pavel Andrei · October 11, 2016
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
    ofstream theFile("players.txt");

    cout << "Enters playrs ID,Name, and Money" << endl;
    cout << "press Ctrl+z to quit\n" << endl;

    int idNumber;
    string name;
    double money;

    while(cin >> idNumber >> name >> money){
        theFile << idNumber << ' ' << name << ' ' << money << endl;
    }

    return 0;
}
+1 Arch38 ツ · October 12, 2016
So i dont see anything wrong with the code you pasted, maybe there is some issue with the Compiler your using?
0 Pavel Andrei · October 12, 2016
Maybe,im using GNU GCC compiler,which is the compiler Bucky was using when he made the video and it worked for him...hmm

Are you sure my code is correct?
+1 Arch38 ツ · October 12, 2016
yeah i even tested it to make sure and it works fine on my end
im using Visual Studios 2015

Also opened up codeblocks and then tried with the compiler your using and it works fine there to so there is nothing wrong with the code youve pasted there has to be some other issue on your end. Try switching the compiler on Codeblocks maybe that will help.
+1 Pavel Andrei · October 13, 2016
Okay,thanks.I'm happy to hear that i didn't do anything wrong.I'm gonna keep trying to solve the issue
+1 Jay Deshaun · October 14, 2016
It could be a cached version from the compiler as compiler's cache previous code and run them instead of the current code.

If not then it could be an input you're entering.
0 Pavel Andrei · October 16, 2016
Problem solved xD
I have no idea what the problem was but i deleted the previous project and created another one and it worked properly
+1 jim Auckerman · November 18, 2016
'Clean' before the build from time to time. (Menu > Build > Clean)
0 axel vincent · November 20, 2016
Code is okay.
You need to download the mingw version for cpp if you work on windows.
  • 1

C++

131,187 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator