|
|
|
#1 (permalink) | ||||||||
|
PC Gamer
|
Right, I have decided that seeing as though it is the summers hols for me that i will go through my SAMs teach yourself book. I will probably to asking for a lot of help
And here is my first question. Why doesn't this work? Code:
#include<iostream>
usingnamespace std;
int main(int argc, char* argv[])
{
int ReturnCode = 0;
float Dividend = 1;
cout << "Dividend: ";
cin >> Dividend;
if (!cin.fail())
{
float Divisor;
cout << "Divisor: ";
cin >> Divisor;
if (!cin.fail())
{
float Result = (Dividend/Divisor);
cout << Result << endl;
}
else
{
cerr << "Input error, not a number?" << endl;
cin.clear();
char BadInput[5];
ReturnCode = 1;
};
}
else
{
cerr << "Input error, not a number?" << endl;
cin.clear();
char BadInput[5];
ReturnCode = 1;
};
char StopCharacter;
cout << endl << "Press a key and \"Enter\": ";
cin >> StopCharacter;
return ReturnCode;
}
Thanks very much Kris
__________________
Kris
|
||||||||
|
|
|
|
|
#2 (permalink) | |
|
Overclocker
|
Quote:
As far as I can tell the error handler is running fine, except you don't have any form of pause to allow the user to view the error. I imagine either you missed a couple lines copying from the book, or the book needs to be updated (a common occurence, sadly). Try adding a line such as "cin >> BadInput;" after the BadInput definition in each of the error handlers, this will work just like the StopCharacter lines towards the end; it will allow the user to view the error message and force the user to enter a character before closing the application.
__________________
DD TDX waterblock DD Maze 4-1 CPU (w. Peltier) Swiftech pump DD reservoir DD radiator Dual heatercore |
|
|
|
|
|
#3 (permalink) | |||||||||||
|
Overclocker
|
try adding this bit of code at the end of your main function:
system("PAUSE"); return EXIT_SUCCESS;
|
|||||||||||
|
|
|
|
#5 (permalink) | ||||||||
|
PC Gamer
|
Well, I may as well ask so that I understand it.
Why is it that it doesn't stop anyway when running these lines: Code:
cout << endl << "Press a key and \"Enter\": "; cin >> StopCharacter;
__________________
Kris
Last edited by kris_cs1 : 06-27-05 at 06:07 PM. |
||||||||
|
|
|
|
|
#6 (permalink) | |
|
Overclocker
|
Quote:
__________________
DD TDX waterblock DD Maze 4-1 CPU (w. Peltier) Swiftech pump DD reservoir DD radiator Dual heatercore |
|
|
|
|
|
#7 (permalink) | |||||||||
|
PC Gamer
|
Quote:
__________________
Kris
|
|||||||||
|
|
|
|
|
#8 (permalink) | ||||||
|
Programmer
|
Quote:
Code:
cout << endl; cout << "Press any key\n"; cin >> StopChar;
Last edited by MrSmiley : 06-28-05 at 01:34 AM. |
||||||
|
|
|
|
#9 (permalink) | |
|
Overclocker
|
Quote:
__________________
DD TDX waterblock DD Maze 4-1 CPU (w. Peltier) Swiftech pump DD reservoir DD radiator Dual heatercore |
|
|
|
|
|
#10 (permalink) | ||||||||||
|
PC Gamer
|
Quote:
Quote:
![]()
__________________
Kris
|
||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|