15,896,118 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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
mondo2
8-Nov-21 7:56am
View
Deleted
Thanks, I will give it a go. Never done loops in C.
mondo2
8-Nov-21 7:56am
View
Deleted
Thank you. I will work on this and come back to you. The code you told me about helps a lot. I haven't done any loops so far in C.
Show More