11 Replies - 391 Views - Last Post: 04 October 2012 - 12:36 AM Rate Topic: -----

#1 osu1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 17-June 12

How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 09:58 PM

Hello, I am having a little rouble with my program. I have been doing everything well but I got stuck in one part. After the user has inputed 3 different numbers in my program, the lowest one has to be dropped and the highest 2 added. Aftwerwards that displays a certain grade. I tried using > and < relational operators but that did not work. I tried to rewrite but have no idea where to go. This is using if and else statements and relational operators.


#include <iostream>
using namespace std;

int main()
{
	int a,b,c;
	
	cout << "Enter the score for test #1:" << endl;
	cin >> a;
	cout << "Enter the score for test #2:"<< endl;
	cin >> b;
	cout << "Enter the score for test #3:" << endl;
	cin >> c;
	
	
	cout << "First test:" << a << endl;
	cout << "Second test:" << b << endl;
	cout << "Third test:" << c << endl; 
	
	if  (   ) 
	{
	 cout << " After dropping test #2, the points earned are" <<  << /
	 cout << "The letter grade is 
	return 0;
} 


Is This A Good Question/Topic? 0
  • +

Replies To: How to drop the lowest number of 3 and display out put

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 10:04 PM

View Postosu1, on 04 October 2012 - 10:28 AM, said:

Hello, I am having a little rouble with my program. I have been doing everything well but I got stuck in one part. After the user has inputed 3 different numbers in my program, the lowest one has to be dropped and the highest 2 added. Aftwerwards that displays a certain grade. I tried using > and < relational operators but that did not work. I tried to rewrite but have no idea where to go. This is using if and else statements and relational operators.


#include <iostream>
using namespace std;

int main()
{
	int a,b,c;
	
	cout << "Enter the score for test #1:" << endl;
	cin >> a;
	cout << "Enter the score for test #2:"<< endl;
	cin >> b;
	cout << "Enter the score for test #3:" << endl;
	cin >> c;
	
	
	cout << "First test:" << a << endl;
	cout << "Second test:" << b << endl;
	cout << "Third test:" << c << endl; 
	
	if  (   ) 
	{
	 cout << " After dropping test #2, the points earned are" <<  << /
	 cout << "The letter grade is 
	return 0;
} 


You need a series of if conditions to make the lowest number get dropped. After that you can add the other 2 variables.

eg.
 if(a<b && a<c)
{
int result = b+c;
}

else if ( b<a && b<c)
{
int result = a+c;
}

else
{
int result= a+b;
}



regards,
Raghav

This post has been edited by raghav.naganathan: 03 October 2012 - 10:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 osu1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 17-June 12

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 10:14 PM

View Postraghav.naganathan, on 03 October 2012 - 10:04 PM, said:

View Postosu1, on 04 October 2012 - 10:28 AM, said:

Hello, I am having a little rouble with my program. I have been doing everything well but I got stuck in one part. After the user has inputed 3 different numbers in my program, the lowest one has to be dropped and the highest 2 added. Aftwerwards that displays a certain grade. I tried using > and < relational operators but that did not work. I tried to rewrite but have no idea where to go. This is using if and else statements and relational operators.


#include <iostream>
using namespace std;

int main()
{
	int a,b,c;
	
	cout << "Enter the score for test #1:" << endl;
	cin >> a;
	cout << "Enter the score for test #2:"<< endl;
	cin >> b;
	cout << "Enter the score for test #3:" << endl;
	cin >> c;
	
	
	cout << "First test:" << a << endl;
	cout << "Second test:" << b << endl;
	cout << "Third test:" << c << endl; 
	
	if  (   ) 
	{
	 cout << " After dropping test #2, the points earned are" <<  << /
	 cout << "The letter grade is 
	return 0;
} 


You need a series of if conditions to make the lowest number get dropped. After that you can add the other 2 variables.

eg.
 if(a<b && a<c)
{
int result = b+c;
}

else if ( b<a && b<c)
{
int result = a+c;
}

else
{
int result= a+c;
}



regards,
Raghav



Ah I see thank you but say after I drop the lowest one, and then i want to classify them like say a+b = 80 is a B grade , and 90 is an A , is this more if/else statements inside of the else statemetns already there?

This post has been edited by osu1: 03 October 2012 - 10:16 PM

Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is online

  • >not activating your almonds
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,672
  • Joined: 24-July 11

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 10:20 PM

You could use a Switch statement to test the value of the result:
switch (result)
{
case >= 90
//return 'A'
break;
case >= 80
//return 'B'
break;
}

This post has been edited by DimitriV: 03 October 2012 - 10:21 PM

Was This Post Helpful? 0
  • +
  • -

#5 osu1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 17-June 12

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 10:25 PM

View PostDimitriV, on 03 October 2012 - 10:20 PM, said:

You could use a Switch statement to test the value of the result:
switch (result)
{
case >= 90
//return 'A'
break;
case >= 80
//return 'B'
break;
}


We have not gotten to switch statements yet so I cant use that. Thank you though.

This post has been edited by osu1: 03 October 2012 - 10:25 PM

Was This Post Helpful? 0
  • +
  • -

#6 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 10:32 PM

View Postosu1, on 04 October 2012 - 10:55 AM, said:

View PostDimitriV, on 03 October 2012 - 10:20 PM, said:

You could use a Switch statement to test the value of the result:
switch (result)
{
case >= 90
//return 'A'
break;
case >= 80
//return 'B'
break;
}


We have not gotten to switch statements yet so I cant use that. Thank you though.


Since you haven't learned switch statements, you can use if statements.

if(result>=90)
cout<<"A grade";
else if(result>=80)
cout<<"B grade";



and so on. :)

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#7 osu1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 17-June 12

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 10:41 PM

View Postraghav.naganathan, on 03 October 2012 - 10:32 PM, said:

View Postosu1, on 04 October 2012 - 10:55 AM, said:

View PostDimitriV, on 03 October 2012 - 10:20 PM, said:

You could use a Switch statement to test the value of the result:
switch (result)
{
case >= 90
//return 'A'
break;
case >= 80
//return 'B'
break;
}


We have not gotten to switch statements yet so I cant use that. Thank you though.


Since you haven't learned switch statements, you can use if statements.

if(result>=90)
cout<<"A grade";
else if(result>=80)
cout<<"B grade";



and so on. :)

regards,
Raghav


Thank you and one last question, I have to repeat this A , B, C grade if/else statements for every drop the lowest grade if/else statements correct?
Was This Post Helpful? 0
  • +
  • -

#8 osu1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 17-June 12

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 10:49 PM

My code completed but it keeps giving me primary expression errors.


Lab4_Ex2.cpp:32: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:36: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:49: error: expected `(' before '<' token
Lab4_Ex2.cpp:99: error: expected `}' at end of input

#include <iostream>
using namespace std;

int main()
{
	int a,b,c;
	
	cout << "Enter the score for test #1:" << endl;
	cin >> a;
	cout << "Enter the score for test #2:"<< endl;
	cin >> b;
	cout << "Enter the score for test #3:" << endl;
	cin >> c;
	
	
	cout << "First test:" << a << endl;
	cout << "Second test:" << b << endl;
	cout << "Third test:" << c << endl; 
	
	if  (a<b && a<c )
	{
	 int result = b+c;
	 if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	 
	 
	 else if <b , a && b < c)
	 {
	 int result = a + c;
	  if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	
	
	
	
	
	 else 
	 {
	 int result = a + c;
	  if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	return 0;
} 

Was This Post Helpful? 0
  • +
  • -

#9 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 10:59 PM

View Postosu1, on 04 October 2012 - 11:19 AM, said:

My code completed but it keeps giving me primary expression errors.


Lab4_Ex2.cpp:32: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:36: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:49: error: expected `(' before '<' token
Lab4_Ex2.cpp:99: error: expected `}' at end of input

#include <iostream>
using namespace std;

int main()
{
	int a,b,c;
	
	cout << "Enter the score for test #1:" << endl;
	cin >> a;
	cout << "Enter the score for test #2:"<< endl;
	cin >> b;
	cout << "Enter the score for test #3:" << endl;
	cin >> c;
	
	
	cout << "First test:" << a << endl;
	cout << "Second test:" << b << endl;
	cout << "Third test:" << c << endl; 
	
	if  (a<b && a<c )
	{
	 int result = b+c;
	 if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	 
	 
	 else if <b , a && b < c)
	 {
	 int result = a + c;
	  if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	
	
	
	
	
	 else 
	 {
	 int result = a + c;
	  if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	return 0;
} 


That was not what I meant. Let the if statements for finding out result be independent.They will help you to remove the lowest value and will calculate the result i.e the sum of the 2 higher values.

once that is finished, you will want to print the grade. For that you should use separate if-else if conditions.

Please do not nest the if statements as you have done.

let them be separate like this.

if(result>=90) cout<<"Grade A";
else if(result>=80) cout<<"Grade B";
else if(result>=70) cout<<"Grade C";
else cout<<"Grade D";



regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3168
  • View blog
  • Posts: 9,581
  • Joined: 05-May 12

Re: How to drop the lowest number of 3 and display out put

Posted 03 October 2012 - 11:39 PM

View PostDimitriV, on 03 October 2012 - 10:20 PM, said:

You could use a Switch statement to test the value of the result:
switch (result)
{
case >= 90
//return 'A'
break;
case >= 80
//return 'B'
break;
}


What language is that? My C/C++ compiler doesn't seem to take that syntax at all.
Was This Post Helpful? 0
  • +
  • -

#11 osu1  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 84
  • Joined: 17-June 12

Re: How to drop the lowest number of 3 and display out put

Posted 04 October 2012 - 12:17 AM

View Postraghav.naganathan, on 03 October 2012 - 10:59 PM, said:

View Postosu1, on 04 October 2012 - 11:19 AM, said:

My code completed but it keeps giving me primary expression errors.


Lab4_Ex2.cpp:32: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:36: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:49: error: expected `(' before '<' token
Lab4_Ex2.cpp:99: error: expected `}' at end of input

#include <iostream>
using namespace std;

int main()
{
	int a,b,c;
	
	cout << "Enter the score for test #1:" << endl;
	cin >> a;
	cout << "Enter the score for test #2:"<< endl;
	cin >> b;
	cout << "Enter the score for test #3:" << endl;
	cin >> c;
	
	
	cout << "First test:" << a << endl;
	cout << "Second test:" << b << endl;
	cout << "Third test:" << c << endl; 
	
	if  (a<b && a<c )
	{
	 int result = b+c;
	 if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	 
	 
	 else if <b , a && b < c)
	 {
	 int result = a + c;
	  if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	
	
	
	
	
	 else 
	 {
	 int result = a + c;
	  if ( result >= 92)
	 {
	 cout << " Your grade is an a" << endl;
	 }
	 else if ( result < 92 || >= 82 )
	 {
	 cout << " Your grade is a b"<< endl;
	 }
	 else if ( result < 82 || >= 72) 
	 {
	 cout << "Your grade is a c" << endl; 
	 }
	 else if ( result < 72)
	 {
	 cout << "Your grade is a d" << endl; 
	 }
	 }
	 
	 
	return 0;
} 


That was not what I meant. Let the if statements for finding out result be independent.They will help you to remove the lowest value and will calculate the result i.e the sum of the 2 higher values.

once that is finished, you will want to print the grade. For that you should use separate if-else if conditions.

Please do not nest the if statements as you have done.

let them be separate like this.

if(result>=90) cout<<"Grade A";
else if(result>=80) cout<<"Grade B";
else if(result>=70) cout<<"Grade C";
else cout<<"Grade D";



regards,
Raghav


I took off the nested statements but still cannot get it to work, it doesnt even get to my if statements at all. Just displays the numbers I inputed.
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3168
  • View blog
  • Posts: 9,581
  • Joined: 05-May 12

Re: How to drop the lowest number of 3 and display out put

Posted 04 October 2012 - 12:36 AM

Post your current code. We are not psychic. We may have a guess as to what you meant by "take off the nested statements", but our guess maybe wrong. It would be better if you just show us what you've done.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1