What's new

Closed Basic C programming problem but till now di ko masolusyunan

Status
Not open for further replies.
Teka hindi ako master. Katulad mo, nag-aaral pa din ako ng C at C++.

Una muna, ano ba gusto mo ma-achieve? Ano ba goal ng program mo? Medyo kasi magulo. Tapos as per my previous reply, kulang yung switch-block mo. Yung switch can be used as an alternative to if-else conditionals. And in some cases it is more preferred.
As I've said sir sample lang yan , I'm almost done with my program ang problem ko nalang is yung true=1 and false=0 para ma achieve ko yung 5/5 na score per week , ang lumalabas kase na output sa week 1 score is 300+ instead of just score=5 kapag tama yung lahat ng sagot
 
Dapat yung score incremental kapag the answer is correct, ie score++

I modified the section 'score' a bit. I also made the char input case-insensitive so if a user entered the correct char regardless if it is in small or capital, it will still count.

Code:
switch(level) {
    char qc,qv;
    case 1:
        printf("\n\nQuestion 1 : Expand IT. \n\nA. Information Technology\nB. Incorporated technology\nC. Information torture\n\nInput Here: ");
        scanf("%s",&qc);
        if (qc == 'A' || qc == 'a') { score++; }
        printf("\n\nQuestion 2 : Expand CPU. \n\nA. Central processing universe\nB. Center phone user\nC. Central processing unit\n\nInput Here: ");
        scanf("%s",&qc);
        if (qc == 'C' || qc == 'c') { score++; }
        printf("\n\nQuestion 3 : Expand RAM.\n\nA. Read and memorize\nB. Random Access Memory\nC. Read and mark\n\n Input Here: ");
        scanf("%s",&qc);
        if (qc == 'B' || qc == 'b') { score++; }
        printf("\n\nQuestion 4 : Expand ROM.\n\nA. Random only memory\nB. Read only memory\nC. Read on motherboard\n\n Input Here:");
        scanf("%s",&qc);
        if (qc == 'B' || qc == 'b') { score++; }
        printf("\n\nQuestion 5 : Expand GPU.\n\nA. Graphics processing unit\nB. Google para umandar\nC. Gold processing unit\n\n Input Here: ");
        scanf("%s",&qc);
        if (qc == 'A' || qc == 'a') { score++; }
        printf("Total score :%d\n", score);
        if(score>=3) {
            printf(" You passed 1st week proceeding to week 2 please wait ...");
        }
        else
        {
            printf(" you failed better luck next time exiting...\n\n");
        return 1;
        }
 
Last edited:
Dapat yung score incremental kapag the answer is correct, ie score++

I modified the section 'score' a bit. I also made the char input case-insensitive so if a user entered the correct char regardless if it is in small or capital, it will still count.

Code:
switch(level) {
    char qc,qv;
    case 1:
        printf("\n\nQuestion 1 : Expand IT. \n\nA. Information Technology\nB. Incorporated technology\nC. Information torture\n\nInput Here: ");
        scanf("%s",&qc);
        if (qc == 'A' || qc == 'a') { score++; }
        printf("\n\nQuestion 2 : Expand CPU. \n\nA. Central processing universe\nB. Center phone user\nC. Central processing unit\n\nInput Here: ");
        scanf("%s",&qc);
        if (qc == 'C' || qc == 'c') { score++; }
        printf("\n\nQuestion 3 : Expand RAM.\n\nA. Read and memorize\nB. Random Access Memory\nC. Read and mark\n\n Input Here: ");
        scanf("%s",&qc);
        if (qc == 'B' || qc == 'b') { score++; }
        printf("\n\nQuestion 4 : Expand ROM.\n\nA. Random only memory\nB. Read only memory\nC. Read on motherboard\n\n Input Here:");
        scanf("%s",&qc);
        if (qc == 'B' || qc == 'b') { score++; }
        printf("\n\nQuestion 5 : Expand GPU.\n\nA. Graphics processing unit\nB. Google para umandar\nC. Gold processing unit\n\n Input Here: ");
        scanf("%s",&qc);
        if (qc == 'A' || qc == 'a') { score++; }
        printf("Total score :%d\n", score);
        if(score>=3) {
            printf(" You passed 1st week proceeding to week 2 please wait ...");
        }
        else
        {
            printf(" you failed better luck next time exiting...\n\n");
        return 1;
        }
still same sir :( total score=65 :(((
 
Ang dami talagang mali.

Paano magiging tama yan eh. Sa mga statement pa lang na ganito oh. Eh mali ka na kaagad. Katulad ng ganito.
Code:
score=qc;
at ito pa.
Code:
score1=qv;


Nag declare ka ng variables na type "int" na kung saan tinawag mong "score" at "score1". Pero nilagyan mo ng values na galing sa variables na "qc" at "qv" na type "char". Ang mangyayari nyan ay ang malalagay na value sa "score" ay ang decimal value ng ASCII code ng character na nasa "qc".

For example : Sa "Easy Level Week 1" questions mo. Punta tayo sa pinakahuli.
Code:
printf("\n\nQuestion 5 : Expand GPU.\n\nA. Graphics processing unit\nB. Google para umandar\nC. Gold processing unit\n\n Input Here:");
qc='A';
scanf("%s",&qc);
delay(2000);
clrscr();
score=qc;
printf("Total score :%d",score);
Ang mangyayari dyan kasi kapag pinili mo ang tamang sagot. Mag i input ka ng letter "A". Ngayon ang magiging value ng "qc" ay "A". Pero pagkatapos naman ay ipinasa mo ang value sa loob ng variable "qc" na type "char" sa variable na "score" na type "int".
Code:
score=qc;
Ang mangyayari nyan ay ang palaging malalagay na value sa variable na "score" ay ang value na "65" na ASCII decimal code sa letter "A" kung palagi ka na sasagot ng tama.

Isa pang malaking mali mo. Wala kang paraan para tingnan kung mali o tama ang sagot. Paano ka mag i increase ng score kung di mo alam kung ang sinagot sa tanong ay tama o mali. For example.
Code:
printf("\n\nQuestion 1 : Expand IT. \n\nA. Information Technology\nB. Incorporated technology\nC. Information torture\n\nInput Here : ");
qc='A';
scanf("%s",&qc);
delay(2000);
clrscr();
printf("\n\nQuestion 2 : Expand CPU. \n\nA. Central processing universe\nB. Center phone user\nC. Central processing unit\n\nInput Here :");
Pagkatapos mo mag display ng tanong at mag recieve ng input para sa sagot dumiretso ka na sa pag display ng susunod ng tanong. Paano mo ngayon malalaman kung tama ba ang sinagot base sa input na nakuha mo, Aber? At nang madagdagan mo ang score. Paano?

Kaya nga binigyan ka ng code na
Code:
if(qc=='A')
{
score++;
}
para sa solusyon. Ilagay mo lang yang code kasunod sa pagkuha mo ng input sa user.


At tsaka isa pa. Bakit ang dami mong code na ganito?
Code:
qc='A';
scanf("%s",&qc);
Bakit? As in palagi. Palagi kang nag a assign ng value sa variable na siya rin na gagamitin agad agad mo na sasalo sa input value mo. As in redundant talaga at walang silbi. Bakit?
 
Problema sa code ni TS, masyado magulo, halu-halo. Kulang ng segmentation by using functions. Tapos yung logic flow, eg so pipili yung user ng level. Say the user chose level 1 (week1). But then again lahat ng conditionals for all weeks, nakapaloob lang sa iisang switch-block, case1.

Try to break it down. Make sure that you can get week 1 to work first before you move on to the other weeks.

Magulo ito.
 
Ang dami talagang mali.

Paano magiging tama yan eh. Sa mga statement pa lang na ganito oh. Eh mali ka na kaagad. Katulad ng ganito.
Code:
score=qc;
at ito pa.
Code:
score1=qv;


Nag declare ka ng variables na type "int" na kung saan tinawag mong "score" at "score1". Pero nilagyan mo ng values na galing sa variables na "qc" at "qv" na type "char". Ang mangyayari nyan ay ang malalagay na value sa "score" ay ang decimal value ng ASCII code ng character na nasa "qc".

For example : Sa "Easy Level Week 1" questions mo. Punta tayo sa pinakahuli.
Code:
printf("\n\nQuestion 5 : Expand GPU.\n\nA. Graphics processing unit\nB. Google para umandar\nC. Gold processing unit\n\n Input Here:");
qc='A';
scanf("%s",&qc);
delay(2000);
clrscr();
score=qc;
printf("Total score :%d",score);
Ang mangyayari dyan kasi kapag pinili mo ang tamang sagot. Mag i input ka ng letter "A". Ngayon ang magiging value ng "qc" ay "A". Pero pagkatapos naman ay ipinasa mo ang value sa loob ng variable "qc" na type "char" sa variable na "score" na type "int".
Code:
score=qc;
Ang mangyayari nyan ay ang palaging malalagay na value sa variable na "score" ay ang value na "65" na ASCII decimal code sa letter "A" kung palagi ka na sasagot ng tama.

Isa pang malaking mali mo. Wala kang paraan para tingnan kung mali o tama ang sagot. Paano ka mag i increase ng score kung di mo alam kung ang sinagot sa tanong ay tama o mali. For example.
Code:
printf("\n\nQuestion 1 : Expand IT. \n\nA. Information Technology\nB. Incorporated technology\nC. Information torture\n\nInput Here : ");
qc='A';
scanf("%s",&qc);
delay(2000);
clrscr();
printf("\n\nQuestion 2 : Expand CPU. \n\nA. Central processing universe\nB. Center phone user\nC. Central processing unit\n\nInput Here :");
Pagkatapos mo mag display ng tanong at mag recieve ng input para sa sagot dumiretso ka na sa pag display ng susunod ng tanong. Paano mo ngayon malalaman kung tama ba ang sinagot base sa input na nakuha mo, Aber? At nang madagdagan mo ang score. Paano?

Kaya nga binigyan ka ng code na
Code:
if(qc=='A')
{
score++;
}
para sa solusyon. Ilagay mo lang yang code kasunod sa pagkuha mo ng input sa user.


At tsaka isa pa. Bakit ang dami mong code na ganito?
Code:
qc='A';
scanf("%s",&qc);
Bakit? As in palagi. Palagi kang nag a assign ng value sa variable na siya rin na gagamitin agad agad mo na sasalo sa input value mo. As in redundant talaga at walang silbi. Bakit?
Pasenya na po master , Newbie palang po kase talaga sa programming kaya po andami ko pa pong mali plus yung functions next week pa ilelesson samin pero nag aadvance study naman ako pero iba parin pag sa hands on na itinuturo sayo , Yung program na ginagawa ko as in ako lang talaga gumawa nyan walang help na galing sa iba kahit na groupings yung project nag solo ako kase parang mas okay sakin kung ako mismo gagawa para matuto ako at hindi ako umasa sa mga kaklase ko , Btw sa room ako lang yung gumawa ng questions na may choices na A,B,C lahat sila naka 1,2,3 ang sabi nila hindi daw gumagana kapag naka char yung gamit , pero i`m finding solutions naman para kahit papano A,B,C yung choices ng questions ko , hirap na hirap lang talaga ako kung pano mapapalabas yung score = 1 kase nga baguhan palang ako limited palang yung mga nalalaman ko at kahit mag search ako sa google ng solutions hindi ko parin magawa kase halos wala talagang sagot sa tanong ko thats why sa mga forums ako nagtatanong para malaman ko yung mga sagot sa katanungan ko . Btw master salamat sa criticism mo, Pagsisipagan ko pa mag aral ng codes salamat po
 
Status
Not open for further replies.

Similar threads

Back
Top