| | |
Having trouble with a else... else if loop (For a class)
Thread Solved
![]() |
•
•
Join Date: Oct 2008
Posts: 17
Reputation:
Solved Threads: 0
My code, in 'full' (only 89 lines, lol) is here. My input file is here and (for kicks and giggles) my outuput file when I comment out the else... if statements and have simply fout is here. (Remove the .txt on the last two...)
I'm having a problem with my if else statement. When I comment out the else if stuff, it works.
(Choice is an int)
Is is supposed to be something like <= and not ==? Choice does either equal 1 or 2, and if it is 3 it skips all of them to the end. But the above code skips over them, even though for it to get out of the while loop it HAD to work.
Does it have something with the preceding do while loop?
I'm sure I made a stupid mistake... indeed, for a while It did not work: I was giving choice the value of 2 or 1 each time! ( else if (choice = 2))
Thanks for the help! I have this due tomorrow, so no matter what I'll be getting it done. I hate getting all of the work (I know easy for some of you, but I'm a beginner) and then something simple stupid not letting it work. And I KNOW a switch would work, but the prof does not want one!
I name my files funny, by the way. The name of the project? Poppus_of_sorrowz. I believe I have more fun making the name than the code itself... although making kickbutt code, above and beyond what the professor wants, is fun. But I'm going for KISS (Keep it simple, stupid) for now, as I don't have time for very pretty code, with extra stuff (as much as I would like to do that! School can be a pain, so much to study for!
I'm having a problem with my if else statement. When I comment out the else if stuff, it works.
(Choice is an int)
c++ Syntax (Toggle Plain Text)
if (choice == 1) { fout << fixed << showpoint << setprecision(2); fout << "The average female gpa is " << AverageFemaleGPA << endl << endl; fout << "The average male gpa is " << AverageMaleGPA << endl << endl; fout << "The overall gpa is " << AverageGPA << endl; } else if (choice == 2) { cout << fixed << showpoint << setprecision(2); cout << "The average female gpa is " << AverageFemaleGPA << endl << endl; cout << "The average male gpa is " << AverageMaleGPA << endl << endl; cout << "The overall gpa is " << AverageGPA << endl; }
Is is supposed to be something like <= and not ==? Choice does either equal 1 or 2, and if it is 3 it skips all of them to the end. But the above code skips over them, even though for it to get out of the while loop it HAD to work.
Does it have something with the preceding do while loop?
c++ Syntax (Toggle Plain Text)
do { cout << "What would you like to do?" << endl << endl; cout << "1. Output the gpa information to an output file." << endl << endl; cout << "2. Display the gpa information on the screen." << endl << endl; cout << "Exit the program." << endl << endl; cout << "Enter your selection:"; cin >> choice; } while (choice!=1 && choice!=2 && choice!=3);
Thanks for the help! I have this due tomorrow, so no matter what I'll be getting it done. I hate getting all of the work (I know easy for some of you, but I'm a beginner) and then something simple stupid not letting it work. And I KNOW a switch would work, but the prof does not want one!
I name my files funny, by the way. The name of the project? Poppus_of_sorrowz. I believe I have more fun making the name than the code itself... although making kickbutt code, above and beyond what the professor wants, is fun. But I'm going for KISS (Keep it simple, stupid) for now, as I don't have time for very pretty code, with extra stuff (as much as I would like to do that! School can be a pain, so much to study for!
Last edited by Avaviel; Oct 31st, 2008 at 1:10 am.
![]() |
Similar Threads
- Removing elements from a list in a loop (Python)
- Hey Just started new topic with arrays, and having some trouble please help (C++)
- Having Some Trouble with Methods (Java)
- Having trouble Subtracting 3 digit #'s help! (VB.NET)
- Trouble with Pointers (C)
- trouble with counting letter from file, please help. (C++)
- Trouble getting code to compile (C++)
- Element is undefined in a Java object of type class [Ljava.lang.String; referenced as (ColdFusion)
- Help with Class, stuck. (C++)
Other Threads in the C++ Forum
- Previous Thread: Array homework help- please help
- Next Thread: Problem in loading VC++ Win32 dll in C#
| Thread Tools | Search this Thread |
ace_thread api array assignment based binary bitmap borland c++ c++endcode c/c++ char class classes code coding compile connect console conversion count delete delete-line deploy desktop developer directshow dll download dynamic dynamiccharacterarray email embedded encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream information input int integer java lib linkedlist linker loop looping loops map math mathhomeworkhelp matrix memory multidimensional multiple news node output pointer problem program programming project python random read recursion reference remote reverse richedit rpg string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





