Click here to Skip to main content
15,896,118 members

Comments by mondo2 (Top 7 by date)

mondo2 9-Nov-21 14:07pm View    
We just have two more weeks of C and we move on to Bash.

Python is the only language we are sticking to for the next few years.
mondo2 9-Nov-21 13:13pm View    
You are not entirely wrong.

Python is a lot easier than C.

I don't know why they are teaching us C, and we only need it for the first 9 weeks and then it's done.

I put the break at the end and it gives me another error message.

main.c:59:5: error: expected expression before ‘}’ token
59 | }
| ^
main.c:62:5: error: break statement not within loop or switch
62 | break; // get out of the loop
mondo2 9-Nov-21 12:26pm View    
I think I read your instructions wrong. I put more brackets and moved the code around. I am not getting repeats. But at some point it broke the whole thing and I get this error:

main.c:61:5: error: expected expression before ‘}’ token
61 | }
| ^
-------------------------------------------------

#include <stdio.h>

int main(void)

{

int number1, number2, sum;
char answer;

while (1) // repeat and repeat
{
break; // get out of the loop
}


{
printf("Enter the first integer to add: ");
scanf("%d",&number1);

printf("Enter the second integer to add: ");
scanf("%d",&number2);
}


printf("Sum of %d and %d = %d \n",number1, number2, sum);

{
if (number1 <= 0)

{
printf("Please choose a number greater than 0 and below 25");
}
else if (number1 > 25)
{
printf("The number must be less than 25");
}

if (number2 <= 0)

{
printf("Please choose a number greater than 0 and below 25");
}
else if (number2 > 25)
{
printf("The number must be less than 25");
}
}

{
sum = number1 + number2;
}

// get the numbers
// check they are in range
// if they are both in range then do the calculation and display the answer
//
{
printf("Do you want another calculation? Y/N");
scanf("%c", &answer);
if (answer == 'N' || answer == 'n')
}



return 0;
}
mondo2 9-Nov-21 11:52am View    
I put the code in. It tends to repeat itself a bit.

Please choose a number greater than 0 and below 25The number must be less than 25Do you want another calculation? Y/NDo you want another calculation? Y/N^C

Do you want another calculation? Y/NDo you want another calculation? Y/N^C

And I can't choose Y. I can only choose N.

What did I do wrong with this code?


#include <stdio.h>

int main(void)

{

int number1, number2;
int sum;

printf("Enter the first integer to add: ");
scanf("%d",&number1);

printf("Enter the second integer to add: ");
scanf("%d",&number2);

sum = number1 + number2;

printf("Sum of %d and %d = %d \n",number1, number2, sum);


if (number1 <= 0)

{
printf("Please choose a number greater than 0 and below 25");
}
else if (number1 > 25)
{
printf("The number must be less than 25");
}

if (number2 <= 0)

{
printf("Please choose a number greater than 0 and below 25");
}
else if (number2 > 25)
{
printf("The number must be less than 25");
}
char answer; // for the question at the end
while (1) // repeat and repeat
{
// get the numbers
// check they are in range
// if they are both in range then do the calculation and display the answer
//
printf("Do you want another calculation? Y/N");
scanf("%c", &answer);
if (answer == 'N' || answer == 'n')

{
break; // get out of the loop
}
}

return 0;
}
mondo2 9-Nov-21 8:28am View    
del