3 days thinking, cant find the error?need help please!!!!

Ask for help with your homework/assignments in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

3 days thinking, cant find the error?need help please!!!!

Postby tuxxy000 » Sat Feb 27, 2010 10:04 pm

i beleve there is an error for the pass condition line... the line shuld be displayed when i enter 13 and 100 as inputs, however, no condition in the entire programm seemed to match the two numbers. please i really need advice. really appreciated thank you.


Code: Select all
// ************I Am having problems with this programit********************

// some of this programm only works on windows cpp
//#include "stdafx.h"// This line is only needd on a windows cpp
#include <iostream>// includes the file iostream
#include <cstdio>
#include <cstdlib>
using namespace std;


int main()


{
for (;;) // for(;;) means that it will be looping for infinity times.
// click the x botton in the window to exit
{


double x,y;
cout <<endl<< "Enter the first grade, then the second grade seperated by a space: ";
// enter what you want the output message should be
// prompting the user for x and y seperated by a space
cin  >> x; // @@@@@ x input of 13   vise versa
cin  >> y; // @@@@@ y input of 100 vise versa
cout << endl;
cout << endl;


if(( x > 100 )||( y > 100))//incase the enter number greater than 100
{
cout<< "Please enter a number between 100 and 0!!"<<endl;
}


else
{
if ((x <0 )||( y < 0))//incase the enter number greater than 100
{
cout<< "Please enter a number between 100 and 0!!"<<endl;
}
}
if ( ( (x >= 0) && (y >= O) )&& ( (x <= 45) && (y <= 45) ) )
{
cout << "Fail!"<<endl;
// What happens if x and y are less than 45
}


else
{
double z;
z = (x + y)/2;


if (100==z)
{
cout << "Congrats! You got a 100% Average!!"<<endl;
// What happens if both x and y are equal to 100
}
else
{
if ( ( (z > 45) && (z< 100) ) && ( ( ( x < 100) && (y < 100) ) || ( (x > 45 ) || ( y > 45) ) ) ) // This line i suspect is the
// problem


{
cout << "You Pass!"<<endl; // Enter outputfor passing
}


}



}
cout << endl;
cout << endl;
cout << "To input two new numbers press any key....... \n\n\n";
system ("pause");// waits to procede, only needed on windows cpp
system ("cls");// clears screen in command window
}


return 0;
tuxxy000
 
Posts: 2
Joined: Sat Feb 27, 2010 9:40 pm

Re: 3 days thinking, cant find the error?need help please!!!!

Postby Alvaro » Sun Feb 28, 2010 5:55 pm

Well, I looked at the conditions in your program, and none seem to match. Which one were you expecting it would match?
User avatar
Alvaro
Moderator
 
Posts: 5180
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Re: 3 days thinking, cant find the error?need help please!!!!

Postby tuxxy000 » Mon Mar 01, 2010 5:46 am

Cold it just be the compiler that is giving me the randome error? Like it missed a line? The correct answer that it should give is you pass! However I seemed to skip that condition
tuxxy000
 
Posts: 2
Joined: Sat Feb 27, 2010 9:40 pm

Re: 3 days thinking, cant find the error?need help please!!!!

Postby Alvaro » Mon Mar 01, 2010 6:08 am

Compilers do have mistakes in them, but not in things this simple. You made a complicated mess with if statements and got lost, which is normal.

Start by posting the exact code that you are compiling. The code above has an O character where it should be a 0, so there's no way that's the code you compiled. If I fix the O to a 0 and I enter 15 and 100, I get "You Pass!".

I also have a readability hint. This code:
Code: Select all
if ( ( (x >= 0) && (y >= O) )&& ( (x <= 45) && (y <= 45) ) )

is the exact same thing as this:
Code: Select all
if (x>=0 && y>=0 && x<=45 && y<=45)


The extra parentheses only make things harder to read.
User avatar
Alvaro
Moderator
 
Posts: 5180
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Re: 3 days thinking, cant find the error?need help please!!!!

Postby markt08 » Wed Mar 03, 2010 6:36 pm

your compiler maybe the reason so your program doesnt run
markt08
 
Posts: 3
Joined: Wed Mar 03, 2010 6:12 pm

Re: 3 days thinking, cant find the error?need help please!!!!

Postby abhishek-sharma » Wed Jul 28, 2010 9:42 pm

if ( ( (x >= 0) && (y >= O) )&& ( (x <= 45) && (y <= 45) ) )

Dude this is typo mistake. Please check in the condition y>0 you have type alphabet O. please chenge this and run this will compile

All the best.
abhishek-sharma
 
Posts: 1
Joined: Wed Jul 28, 2010 6:34 am


Return to Homeworks

Who is online

Users browsing this forum: No registered users and 2 guests

cron