Getting data and reporting errors

Kind of a novice but please bare with me :)

At this stage I will obtain Dimensions A, B & C. But after this before I do the pythagoras equation using the data I want it checked over. I think I've done this here but I'm not sure. I want it to report the message "Invalid Data" if Dimension A is not the longest.


cout << "Enter Dimension A:-";
cin >> DimA;

cout << "Enter Dimension B:-";
cin >> DimB;

cout << "Enter Dimension C:-";
cin >> DimC;

if (DimA >= DimB, DimC)
cout << endl << "Invalid Data";

You will need to change your if statement in order for this to work out. In your code, the comma plus DimC has no effect. Your code does not match your described goal, either.

Try this:

if (dimA <= dimB || dimA <= dimC)
cout << "Invalid Data";
I don't understand what you're asking.
Thanks Captaincjm.

To Avilius:

Here is the original pseudocode I'm working on:

module Main()

begin
get Batch code

while Batch code is greater than blank

get DimensionA
get DimensionB
get DimensionC

if DimensionA is not longest
report error to user – 'Invalid data'


And here is what I've done so far but it's not really working well:

#include <iostream>
using namespace std;

float Main()
(double DimA; double DimB; double DimC;


cout << "Enter Dimension A:-"; /
cin >> DimA;

cout << "Enter Dimension B:-";
cin >> DimB;

cout << "Enter Dimension C:-";
cin >> DimC;

if (dimA <= dimB || dimA <= dimC)
cout << "Invalid Data";
)


So basically I want to enter three Dimensions (A, B & C). And if A is not the longest (biggest number) then a message will appear telling the user that it is Invalid Data and should reenter different data for Dimension A.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

// You're not allowed to have a "float" for the return value of the main function. It must be "int."
// Main should also be lowercase.
float Main()
( // should be {

double DimA; double DimB; double DimC;


cout << "Enter Dimension A:-"; / // Stray forward slash!
cin >> DimA; 

cout << "Enter Dimension B:-";
cin >> DimB;

cout << "Enter Dimension C:-";
cin >> DimC; 

if (dimA <= dimB || dimA <= dimC)
cout << "Invalid Data";
) // should be } 


Try using loops or gotos to request for input again.
Last edited on
Thanks Avilius but I keep getting undeclared identifier on DimA, DimB & DimC.

Did you fix what I told you to fix?
yeah
Paste what you have now.
#include <iostream>
using namespace std;

int main()
{
double DimA; double DimB; double DimC;

cout << "Enter Dimension A:-";
cin >> DimA;

cout << "Enter Dimension B:-";
cin >> DimB;

cout << "Enter Dimension C:-";
cin >> DimC;

if (dimA <= dimB || dimA <= dimC)
cout << "Invalid Data";
}
if (dimA <= dimB || dimA <= dimC)Why is the first letter of the variables lowercase?
Oversight on my part there :) It now works, well kind of. So I can input the Dimensions but once I've entered the last Dimension (C) it nows closes the program. It doesn't show the "Invalid Data" message as it should.
It's because it's closing out too fast.

Try adding
cin.get();
At the end.
Sorry but it hasn't had an affect. Same as before.

Actually it shows really "Invalid Data" but you have to really focus or you'll miss it. Didn't before :)
Last edited on
Try flushing the buffer first.
Finally :) Thank you for all your help! Have a Happy New Year aswell!
Topic archived. No new replies allowed.