473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

not sure what im doing wrong with these if else statements

1 New Member
the first one works but the second does not when its called upon later

if (major == 1)
{
if (gpa > largestm1)
{
largestm1 = gpa;
highnamem1 = last;

}

else if (major == 2)
{

if (gpa > largestm2)
{
largestm2 = gpa;
highnamem2 = last;
}

}

and the next one wont work correctly at all

if (credits <= 30)
{
credits1 = students;
}
else if (credits >=31 && credits <=60)
{
credits2 = students;
}
else if (credits >=61 && credits <=90)
{
credits3 = students;
}
else if (credits >=90)
{
credits4 = students;
}
}

I appreciate any help you can give
Apr 26 '10 #1
2 1134
Fr33dan
57 New Member
When trying to determine errors with nested code blocks indenting each block in helps you see errors:
Expand|Select|Wrap|Line Numbers
  1. if (major == 1)
  2. { // Indent starting here because this is the start 
  3.   // of a code block.
  4.     if (gpa > largestm1)
  5.     {
  6.     largestm1 = gpa;
  7.     highnamem1 = last;
  8.  
  9.     }
  10.   // Now we know the next statement shouldn't go in the
  11.   // code block because it's not indented
  12. } // and we can see that we missed the end bracket.
  13. else if (major == 2)
  14. {
  15.  
  16.     if (gpa > largestm2)
  17.     {
  18.     largestm2 = gpa;
  19.     highnamem2 = last;
  20.     }
  21.  
  22. }
Expand|Select|Wrap|Line Numbers
  1. if (credits <= 30)
  2. {
  3.     credits1 = students;
  4. }
  5. else if (credits >=31 && credits <=60)
  6. {
  7.     credits2 = students;
  8. }
  9. else if (credits >=61 && credits <=90)
  10. {
  11.     credits3 = students;
  12. }
  13. else if (credits >=90)
  14. {
  15.     credits4 = students;
  16. }
  17. } // We should end go back a step at the end bracket 
  18.   // but we don't have anywhere to go so this must
  19.   // be an accidental extra (possibly added to stop 
  20.   // missing bracket errors).
Apr 27 '10 #2
jkmyoung
2,057 Recognized Expert Top Contributor
What does students refer to?
What do credits1, credits2, credits3, and credits4 refer to?
Apr 27 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2486
by: Bart Nessux | last post by:
Should an if statement have a corresponding else statement? Or, is it OK to have an if statement by itself. For completeness, it seems the two should be together, but from experience I know that a...
11
1535
by: AJ | last post by:
here's the scenario.. I am running a DTS to collect the summarized info from Oracle database into SQL server. I then have a update job which updates my transactional table from the summarized...
16
2050
by: Shelly | last post by:
(posted previously on comp.lang.php but no response received. Cross-posted in the dreamweaver forum) I am confused about what goes on with method POST. Here is an overview of a my code,...
0
1284
by: John Phelan | last post by:
I had a very large number of query statements that I had converted to SQL a long time ago aticipating that I would some day upsize my application. Every now and then when I do an import to a new...
0
1220
by: jpatrick | last post by:
I had a very large number of query statements that I had converted to SQL a long time ago aticipating that I would some day upsize my application. Every now and then when I do an import to a new...
4
1280
by: Stefan Kowalski | last post by:
I recently posted a question which was answered by Allen Browne and gave me some tips to structure the tables. However, when it comes to searching the database, performance is unacceptably slow...
9
1453
by: David Teran | last post by:
Hi, we are currently using another database product but besides some licensing issues we are finding more and more problems with the database. We are evaluating PostgreSQL and it looks quite...
42
3385
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
4
2011
by: robinsand | last post by:
Header File: car.h #if !defined CAR_H #define CAR_H enum TCarType { ctEconomy = 1, ctCompact, ctStandard, ctFullSize, ctMiniVan, ctSUV }; class Car { public: Car();
16
1892
by: SirG | last post by:
I'm looking for an explanation of why one piece of code works and another does not. I have to warn you that this is the first piece of Javascript I've ever written, so if there is a better way or a...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.