Eirik
And download
Just open up a terminal and type: clang
Arun
Thank you Rose
Eirik
And download
Alternatively you could try installing Geany. I am pretty sure it ships with GCC. So you'd have a text editor and just have to click the "compile" button to run it
Eirik
Has anyone here ever tried the Tiny C Compiler?
Nana
Hello guys, I just wrote this code but it cannot catch string errors. Pls help me
Nana
#include <iostream> #include "Rectangle.h" #include <iomanip> using namespace std; void intro(); int main() { intro(); double rectLen; double rectWidth; Rectangle rect; bool tryAgain = true; cout<<"\t\tEnter the length of the rectangle: "; cin>>rectLen; cout<<endl; while(tryAgain) { try { rect.setLength(rectLen); tryAgain = false; } catch(Rectangle::NegativeLength e) { cout<<"\t\t"<<e.getValue()<<" is a negative number\n"; cout<<"\t\tEnter a positive number: "; cin>>rectLen; cout<<endl; } } tryAgain = true; cout<<endl; cout<<"\t\tEnter the width of the rectangle: "; cin>>rectWidth; cout<<endl; while(tryAgain) { try { rect.setWidth(rectWidth); tryAgain = false; } catch(Rectangle::NegativeWidth e) { cout<<"\t\t"<<e.getValue()<<" is a negative number\n"; cout<<"\t\tEnter a positive number: "; cin>>rectWidth; cout<<endl; } } cout<<endl; cout<<"\t\tHere is the rectangle's information\n"; cout<<endl; cout<<fixed<<setprecision(2)<<showpoint; cout<<"\t\tLENGTH: "<<rect.getLength()<<"cm"<<endl; cout<<"\t\tWIDTH: "<<rect.getWidth()<<"cm"<<endl; cout<<"\t\tAREA: "<<rect.getArea()<<"squared cm"<<endl; return 0; } void intro() { cout<<"\t\tThis program returns error value in error functions\n"; cout<<"\t\t-----------------------------------------------------\n"; cout<<endl; }
Nana
#include <iostream> #include "Rectangle.h" #include <iomanip> using namespace std; void intro(); int main() { intro(); double rectLen; double rectWidth; Rectangle rect; bool tryAgain = true; cout<<"\t\tEnter the length of the rectangle: "; cin>>rectLen; cout<<endl; while(tryAgain) { try { rect.setLength(rectLen); tryAgain = false; } catch(Rectangle::NegativeLength e) { cout<<"\t\t"<<e.getValue()<<" is a negative number\n"; cout<<"\t\tEnter a positive number: "; cin>>rectLen; cout<<endl; } } tryAgain = true; cout<<endl; cout<<"\t\tEnter the width of the rectangle: "; cin>>rectWidth; cout<<endl; while(tryAgain) { try { rect.setWidth(rectWidth); tryAgain = false; } catch(Rectangle::NegativeWidth e) { cout<<"\t\t"<<e.getValue()<<" is a negative number\n"; cout<<"\t\tEnter a positive number: "; cin>>rectWidth; cout<<endl; } } cout<<endl; cout<<"\t\tHere is the rectangle's information\n"; cout<<endl; cout<<fixed<<setprecision(2)<<showpoint; cout<<"\t\tLENGTH: "<<rect.getLength()<<"cm"<<endl; cout<<"\t\tWIDTH: "<<rect.getWidth()<<"cm"<<endl; cout<<"\t\tAREA: "<<rect.getArea()<<"squared cm"<<endl; return 0; } void intro() { cout<<"\t\tThis program returns error value in error functions\n"; cout<<"\t\t-----------------------------------------------------\n"; cout<<endl; }
MAIN.CPP
Nana
#ifndef RECTANGLE_H #define RECTANGLE_H class Rectangle { public: void setLength(double); void setWidth(double); double getLength() const { return length; } double getWidth()const { return width; } double getArea()const { return length * width; } class NegativeLength { private: double value; public: NegativeLength(double val) { value = val; } double getValue() const { return value; } }; class NegativeWidth { private: double value; public: NegativeWidth(double val) { value = val; } double getValue() const { return value; } }; private: double length; double width; }; #endif // RECTANGLE_H
Nana
#include "Rectangle.h" void Rectangle::setLength(double len) { if(len >= 0) length = len; else throw NegativeLength(len); } void Rectangle::setWidth(double w) { if(w >= 0) width = w; else throw NegativeWidth(w); }
Nana
Pls I'm waiting for your feedback
Nana
It's unfortunate that the source code is not well organized. Pls you can send me a private message for the source code if only you wanna assist me
Good Bye World
Hi group, sorry if this is a repeated question here, but I'm feeling a bit lost and would appreciate some help. I learned a bit of C++ and C in high school, and went on to work as a C++ dev (C++ 03 version) for a year before switching to mostly C# and Python. I lost touch with C++ completely and it has been kind of intimidating to me ever since the more recent versions have come along and I feel I'm too far behind everyone else. Can someone point me in the right direction so I can catch up on the latest versions of C++ and get a bit more familiar with the language?
Kaashᅠ
wht happened ?
Kaashᅠ
thanks, now its opened, i returned back previously bcoz the site wasn't opening
J
For GCC, I will stick with something like Manjaro than void. Also, I wouldn't recommend Arch unless they know something about Linux. (Example, Recent bluez(Bluetooth) bug.)
\Device\NUL
Use Artix if want init freedom arch or Devuan for init freedom debian
Anonymous
hi...I'm a biginner(c++). Am trying to reverse all the characters of a sentence...plz anyone help me to correct the errors. #include <iostream> using namespace std; int main(){ cout<<"\n\nInput your message : "; int size=100; char string[size]; cin>>string; char rev_string[100]; int j = 0; for (int i = 100; i < 0; i--){ while(string[j] =! NULL){ string[j] = rev_string[i]; j++; }break; }cout<<rev_string; return 0; }
Prince Of Persia
string is array of std::string and rev_string is array of char. You should use macro too for size
He hasn't include <string> so he has no problem to name (except readability)
\Device\NUL
Oh sorry, i miss read it
\Device\NUL
> string[j] = rev_string[i];
You forget to make rev_string contain NULL character
Prince Of Persia
\Device\NUL
He even has worse mistake
Idk why he use for loop that has break; keyword without any conditional
\Device\NUL
People still ignoring compiler messages '-'
Prince Of Persia
\Device\NUL
😂I did this
Okay i got it i is 100
Prince Of Persia
Prince Of Persia
The loop is so confusing
Prince Of Persia
He could have done this much better
Prince Of Persia
By a single loop and other thing is the rev_string always contains the last character in string
Prince Of Persia
If the string is "abcdef" rev_string would be "fffffffff..."
Prince Of Persia
Oh what's that break😐
Prince Of Persia
This code has many wonders😂
\Device\NUL
int size = 100 Using size as a dimension for string is problematic use this instead constexpr int x = 10; size of an array should be know at compile time
> size of an array should be know at compile time. Because it's using defined variable, it's not a VLA. Even though the output of -E isn't expanded.
Morax
#include <iostream> using namespace std; int main() { int n; cin>>n; int i; for(i=2;i<n;i++){ if(n%i==0){ break; } } if(i==n){ cout<<"Prime"; } else cout<<"Not prime"; return 0; }
Morax
this is a program to tell whether a given number is prime or not
Morax
but if i do.... for(i=2;i<=n;i++)
Morax
the program still works fine
Morax
someone pls explain this...
Pavel
but if i do.... for(i=2;i<=n;i++)
You actually can check up to n/2, e.g. if you have 31, then dividing by 16 doesn't make sense already since 2 was checked So the checks above n/2 don't really add value
Pavel
But I see you asking about a different thing
Pavel
but if i do.... for(i=2;i<=n;i++)
So, in this case the n+1 will not be reached because it will break on your condition when i == n, because any value is divisible by itself without reminder
Pavel
I think there are even more optimal ways of doing that (which I heard of but can't understand :))
Anonymous
hey
Anonymous
Azure RDP available
Gilded
\Device\NUL
More like : "Can you optimized my code" But you didn't provide your code
\Device\NUL
Maybe your code is too complex.
Anonymous
Don't use online for serious code compilation
\Device\NUL
redacted
artemetra 🇺🇦
artemetra 🇺🇦
use a for loop
\Device\NUL
The conditional is too complex too
\Device\NUL
for(; a <= b; a++) { switch (a) //bla-bla-blah } std::cout << b % 2 ? "odd" : "even"
Prince Of Persia
I read this before I read the question I thought this is some kind of kernel code🥲 but after reading the question ...
\Device\NUL
The code is too complex for this question, You don't even need if (a == b) line. It's include on while (a <= b) block
Prince Of Persia
for(; a <= b; a++) { switch (a) //bla-bla-blah } std::cout << b % 2 ? "odd" : "even"
+ don't use a case without a break that's too complex don't worry about speed😅 (I have done the same only for speed in creating a programming language interpreter just because it was a bit faster in my case)
Prince Of Persia
I think It's just stupid to use multiple conditional using if else more than 3 lines
🥲could even use a array of strings like std::string numbers[] = {"one","two",...};
\Device\NUL
I prefer pointer of char that allocated in data segment
Prince Of Persia
I prefer pointer of char that allocated in data segment
yeah that's better but in C++11 and more that's not recommended