Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. having problems with cin "go figuere :)"

having problems with cin "go figuere :)"

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SilverShalkin
    wrote on last edited by
    #1

    ok... in this code... you dont have to worry where everything is being defined or what headers im using,... wheres my functions... this is just the main program... It all works the first time through, then, the cin stops working: int main() { for(;;)//main loop { gets(SName); cin >> SGPA; person.SetName(SName); person.SetGPA(SGPA); cout << person.GetName() << endl << endl; //print name that you just typed. for(int inc = 0;inc < NN;inc++) //print all names. { cout << Names[inc] << "\t" << GPAS[inc] << endl; } inc = 0; }//end main loop. return 0; } in the program is waits for input for the name of sombody... then it goes on to the next thing... which is my cin statment, asking for the float "GPA" of the persons name you put in. after the first time you run through the on going loop... your not able to insert a GPA, rather, for every new name you put in... it applies the original GPA to the names. Q~How do i reset my cin or get it to work everytime in the loop. set it to null? Thanks! ~SilverShalkin :rose: i have a fealling that it might not be the cin :(, but i'll see in a bit :)

    C 1 Reply Last reply
    0
    • S SilverShalkin

      ok... in this code... you dont have to worry where everything is being defined or what headers im using,... wheres my functions... this is just the main program... It all works the first time through, then, the cin stops working: int main() { for(;;)//main loop { gets(SName); cin >> SGPA; person.SetName(SName); person.SetGPA(SGPA); cout << person.GetName() << endl << endl; //print name that you just typed. for(int inc = 0;inc < NN;inc++) //print all names. { cout << Names[inc] << "\t" << GPAS[inc] << endl; } inc = 0; }//end main loop. return 0; } in the program is waits for input for the name of sombody... then it goes on to the next thing... which is my cin statment, asking for the float "GPA" of the persons name you put in. after the first time you run through the on going loop... your not able to insert a GPA, rather, for every new name you put in... it applies the original GPA to the names. Q~How do i reset my cin or get it to work everytime in the loop. set it to null? Thanks! ~SilverShalkin :rose: i have a fealling that it might not be the cin :(, but i'll see in a bit :)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      cin.flush() should solve your problems, I reckon. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups