Jump to content
Sign in to follow this  
angleboy90

Output Tak Kuar

Recommended Posts

aku guna macam nie


char grade;

pastu utk if else guna macam nie plak

CODE
if(purata2 >= 80) {
grade = 'A';
} else if (purata2 >= 75) {
grade = 'B+';
} else if (purata2 >= 70) {
grade = 'B';
} else if (purata2 >= 65) {
grade = 'C+';
} else if (purata2 >= 50) {
grade = 'C';
} else if (purata2 >= 40) {
grade = 'D';
}else {
    grade = 'E';



tapi utk output B+ dan lain2 yang ada simbol + dia kuar + je

nape ek

boleh tlg ?

Share this post


Link to post
Share on other sites
Name : char
Description : Character or small integer
Size : 1byte

Range
signed: -128 to 127
unsigned: 0 to 255

sepatutnya IDE ko akan bagi warning macam ni.
[Warning] multi-character character constant //aku guna Dev-C++
meaning yang char hanya boleh receive 1byte je. so dalam kes ko nih, just dapat '+' instead of full 'B+' or 'C+'
so cuba work around benda ni dengan include library macam string dalam program ko.

CODE
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main(){
int purata2;
purata2 = 76;

string grade;

if(purata2 >= 80) {
grade = "A";
} else if (purata2 >= 75) {
grade = "B+";
} else if (purata2 >= 70) {
grade = "B";
} else if (purata2 >= 65) {
grade = "C+";
} else if (purata2 >= 50) {
grade = "C";
} else if (purata2 >= 40) {
grade = "D";
}else {
    grade = "E";
}

cout<<"huuuuuuuuu "<<grade;
system ("pause");
return 0;
}


edit - additional explanation Edited by MatchMaker

Share this post


Link to post
Share on other sites
char grade = 'AB' dia amik satu nilai jer. kalo ank amik AB tu leh wat string grade="AB". tak pun char grade[]="AB"... errr betul ke. hehehehe dah lma tinggai c nih..

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...