Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 4th, 2005, 2:14 AM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4 TecBrain is on a distinguished road
'C-' and 'C+'

char ch;


After I input the character:
std::cin>> ch;

And check for the value

EX:

if((ch=='C-') || (ch=='C+'))

do .......

But it not seems to be working, I get an error that C- and C+ are dublicated values.....
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old May 4th, 2005, 2:35 AM   #2
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
try double quotes instead of single quotes

if((ch=="c-") || (ch=="c+"))
Berto is offline   Reply With Quote
Old May 4th, 2005, 3:30 AM   #3
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Would reading more than one character into a char have anything to do with it?
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old May 4th, 2005, 4:59 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
good point you will have to use strcmp to compare the strings
Berto is offline   Reply With Quote
Old May 4th, 2005, 5:58 AM   #5
BaroN NighT
Programmer
 
Join Date: Mar 2005
Location: USA
Posts: 60
Rep Power: 4 BaroN NighT is on a distinguished road
char allocates memory for only one character. While each C- and C+ consists of two characters. So if you want to compare C- with C+, you will have to declare ch as a string not a char. And then you will have to use double quotes in the if, because its a string.
BaroN NighT is offline   Reply With Quote
Old May 4th, 2005, 10:35 AM   #6
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4 TecBrain is on a distinguished road
Thanks Guys that was helpful. I'll Post the code soon
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.

Last edited by TecBrain; May 4th, 2005 at 10:37 AM.
TecBrain is offline   Reply With Quote
Old May 4th, 2005, 10:51 AM   #7
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4 TecBrain is on a distinguished road
Ok, here is the code; I would appreciate any comments and feedback, Thanks.

Its little program that calculate your GPA

#include <iostream>
#include <stdlib.h>

using namespace std;


int main()
{
	int i,credit=0,classes=0,totalcredit=0;
	char ch;
	float newavg=0,total=0,oldGpa=0,result=0;
	string grade;
	
	float const max1=4;
	float const max2=3.7;
	float const max3=3.3;
	float const max4=3;
	float const max5=2.7;
	float const max6=2.3;
	float const max7=2;
	float const max8=1.7;
	float const max9=1.3;
	float const max11=1;
	float const max12=0.7;
	
	
	std::cout << "How Many courses Are You Taking: " << '\n';
	std::cin >> classes;

	
	for(i=1;i<=classes;i++)
	{
		std::cout << "Enter Your " << i << " Grade " << '\n';
		std::cin >> grade;
		std::cout << "What is the Credits of this Course: " << '\n';
		std::cin >> credit;
		
		
		
		if((grade=="A") || (grade=="a"))
		
			total = float(max1 * credit);
			
			
			else if((grade == "A-") || (grade=="a-"))
		
			
			total = float(max2 * credit);
			
					
			else if((grade == "B+") || (grade=="b+"))
			
			total = float(max3 * credit);
			

			else if((grade == "B") || (grade=="b"))
			
			total = float(max4 * credit);
			

			else if((grade == "B-") || (grade=="b-"))
			
			total = float(max5 * credit);
		

			else if((grade == "C+") || (grade=="c+"))
			
			total = float(max6 * credit);
			

			else if((grade == "C") || (grade=="c"))
			
			total = float(max7 * credit);
		

			else if((grade == "C-") || (grade=="c-"))
			
			total = float(max8 * credit);
			

			else if((grade == "D+") || (grade=="d+"))
			
			total = float(max9 * credit);
		

			else if((grade == "D") || (grade=="d"))
			
			total = float(max11 * credit);
		

			else if((grade == "D-") || (grade=="d-"))
			
			total = float(max12 * credit);
			
		
		totalcredit += credit;	
		result += total;
		
	}
	
	
	std::cout << "Your Total GPA is: " << (float(result) / totalcredit);
	
	std::cout << "Do You To have the AVG of more than one GPA (Y,N)" << '\n';
	std::cin >> ch;

	
	
	if((ch=='y') || (ch=='Y'))
	{

		std::cout << "Enter Your Previous GPA: " << '\n';
		std:: cin >> oldGpa;
		newavg = (float((result / totalcredit) + oldGpa) / 2);
	}
	else if((ch=='n') || (ch=='N'))
	{
		newavg = (float(result) / totalcredit);
	}
	std::cout << "Your GPA is:  " << newavg << "  Study harder " << '\n';
	

  system("PAUSE");	
  return 0;
}
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old May 4th, 2005, 10:54 AM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Looks good. However, I would suggest putting all those grade boundaries in an array.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 4th, 2005, 11:07 AM   #9
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4 TecBrain is on a distinguished road
mmm... u mean sth like this:

EX: int A[10] grades{A,A-,B+,.....}

if so how will I assign values.
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old May 4th, 2005, 12:54 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
This is how I would do it:
#include <iostream>
#include <stdlib.h>

using namespace std;


int main()
{
	int i = 0;
	int classes = 0;
	
	string grade = "";
	int credit = 0;
	
	int totalcredit = 0;
	float total = 0;
	float result = 0;
	float oldGPA = 0;
	
	char ch = '\0';
	
	float boundaries[] = { 4.0,  3.7,  3.3,  3.0,  2.7,  2.3,  2.0,  1.7,  1.3,  1.0,  0.7 };
	string grades[] =    { "A",  "A-", "B+", "B",  "B-", "C+", "C",  "C-", "D+", "D",  "D-" };
	
	std::cout << "How many courses are you taking? ";
	std::cin >> classes;

	
	for(i = 1; i <= classes; i++)
	{
		std::cout << "Enter Grade #" << i << ": ";
		std::cin >> grade;
		std::cout << "Enter the Course Credit: ";
		std::cin >> credit;
		
		grade[0] &= 0xDF;
		
		for (int j = 0; j < 11; j++)
		{
			if (grade == grades[j])
			{
				total += boundaries[j] * credit;
				totalcredit += credit;	
			}
		}
		
	}
	
	std::cout << "Your Total GPA is: " << (total / totalcredit) << endl << endl;
	
	std::cout << "Do you want to know the average of more than one GPA? (y/n) ";
	std::cin >> ch;
	ch &= 0xDF;

	if (ch == 'Y')
	{

		std::cout << "Enter Your Previous GPA: ";
		std:: cin >> oldGPA;
		result = (((total / totalcredit) + oldGPA) / 2);
	}
	else
	{
		result = (float(total) / totalcredit);
	}
	std::cout << endl;
	
	std::cout << "Your GPA is: " << result << endl << endl;
	std::cout << "Keep studying!" << endl << endl;
	
	std::cout << "Press any key to continue...";
	getchar();
	return 0;
}
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC