#include "stdafx.h"
#include <iostream>
#include <string>


using namespace std;


int _tmain(int argc, _TCHAR* argv[])

{
	const int Grade1 = 0 ; 29;
	const int Grade2 = 30 ; 39;
	const int Grade3 = 40 ; 69;
	const int Grade4 = 70 ; 100;
	int Grade ;
	int i = 0 ;
	while (i < 100) 
	{
	cout << "Enter Students Grade" ;
    cin >>  Grade ;

	if ( Grade >= 0 && Grade < 29)
        cout << Grade1 << "*";

	else if (Grade >= 30 && Grade < 39)
		cout <<Grade2 << "*";

	else if (Grade >= 40 || Grade < 69)
		cout << Grade3 << "*";

	else (Grade >= 70 || Grade < 100)
	;	cout << Grade4 << "*"; 
	;
	
	}
	i++;
	


		return 177;
		
}

Basically i cant get the const int grade1,2,3,4 to be like 0-29 i dont no what to put in between to seprate them because its supposed to be 0 to 29 and the 30 to 39 after entering this i want is to count the grade and show a table at the end of the program
0-29 ***
30-39 *****
40-69 ********
70-100 ****

stars would be representing how many students got a grade in between them or equavilant.. need help pleasee

Edited 5 Years Ago by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

First, when posting code, please use code tags. We can't even begin to provide effective help if we can't read your post.

#include <iostream>
int main() {
  std::cout << "This looks nice, and is easily readable." << std::endl;
  return 0;
}[/CODE]

#include <iostream>
int main() {
  std::cout << "This looks like dung, and isn't readable." << std::endl;
  return 0;
}

Second, don't mark your threads as !!!!URGENT!!!! it actually makes fewer people look at it rather than more. It may be urgent for you, but it's not urgent for us. This tag usually signals a student looking for a last-minute solution on a silver platter which we won't provide.

Third, the structure of your if statements is upside-down. You should check the larger values first. It makes the logic much less complex.

Fourth, you aren't storing anything for later use. All your code does is belch something out every time there is an input. I think you should get a pen and paper and take some time to think about your overall algorithm. You need a counter for each grade range and you need a section of code, after your loop, that is dedicated to analyzing the input and producing the desired output. As written, everything is jumbled together in a disorganized mess. The structure of the program isn't completely correct, but it could work as an intermediate testing code to make sure your if statements are working correctly. Unfortunately, that's about the only purpose it could serve, if you can get it to work.

And Fifth,

const int Grade1 = 0 ; 29;
const int Grade2 = 30 ; 39;
const int Grade3 = 40 ; 69;
const int Grade4 = 70 ; 100;[/CODE]
This looks like your trying to store ranges.  That's not possible.  You can only store one value in any given variable (unless said variable is an array, but that's different in more ways than 1).  I think you have a good idea here (using a constant to separate each level), but your implementation isn't even close.  It should be more like this:[CODE]
const int MAX_GRADE = 100;
const int GRADE_LEVEL_1 = 88;
const int GRADE_LEVEL_2 = 78;
//etc...

Edited 3 Years Ago by happygeek: fixed formatting

const int Grade1 = 0 ; 29;
const int Grade2 = 30 ; 39;
const int Grade3 = 40 ; 69;
const int Grade4 = 70 ; 100;

yes i have done it like this but when entering a number in between the figures the cout is different for example if i enter 23 it return 0*70* which is wrong as it should display as 0-29 * and then i want to do the store function so it counts and put it in a histogram

>>if i enter 23 it return 0*70* which is wrong
That's because Grade1 isn't "0-29", it's 0 and your if statement that is controlled by Grade4 is built wrong, so the statement after it executes whether you intend it to or not, that's why you get the "70*" part of it. I'll bet that if you enter 32 you get 30*70*. It's for the same reasons. Both your declarations and if statements are built incorrectly.

>>it should display as 0-29 *
It won't display that unless you tell it to. You haven't told it to display that anywhere.

Edited 5 Years Ago by Fbody: n/a

@Alyboi your delete request is denied since this thread does not break any forum rules. Besides it would be unfair toward Fbody since he helped you with it.

Remember whitespace. The ";" operator is what the compiler uses to identify a new line. When you write:

int grade1 = 0; 30;

The compiler reads it as:

int grade1 = 0; //end of the variable!!
30;

If you want to compare between to numbers (0 - 30), you can't do it with a single variable. Your program is confusing the computer and frankly it's confusing me as well.

I'd suggest at this point you just delete this and start from scratch. Sit down, figure out what you need to do. Remember that the "=" operator means "this = that". How can something both be 0 and 30?

Remember what if statements do. They check for a condition (such as equivalence) and executes their contents if the condition is met.

You seem to be USING everything you need, you're not using any of it properly, however.

This article has been dead for over six months. Start a new discussion instead.