Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

summation with if, possible???

+1 vote
asked Feb 8, 2020 by Pedro Alberth (130 points)

i made a questionnaire in c, and everything worked until i try to make a summatory with if, if the answer is right its suppoused to add one,  the questionnaire  consists of 31 questions with 4 possible answers, example:

//i use a integer arrangement with 30 spaces for each answere just like this: int ans[30]={}; 

question 1 with correct answer equal to 1 (which is saved in &ans[0] )

if(ans[0] = 1 ){

     i = s+1 //Ramdom variables i and s and  s equal to 0 in the boxing allocation

finnaly i try to print i (after 31 times doing the thing above)

but the result is always 31 no mather if i answer every one wrong

1 Answer

0 votes
answered Feb 12, 2020 by gameforcer (2,990 points)

if(ans[0] = 1 ){

This line is wrong. Single '=' sign means assignment, while '==' compares values from left and right of these signs. Simply change everywhere accordingly to

if(ans[0] == 1 ){

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.