![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4
![]() |
'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. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
|
|
|
|
|
|
#3 |
|
Professional Programmer
|
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;} |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
good point you will have to use strcmp to compare the strings
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Mar 2005
Location: USA
Posts: 60
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Looks good. However, I would suggest putting all those grade boundaries in an array.
|
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#10 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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;
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|