My eyes are destroyed, so I'm using a screen reader. Whenever I post some codes to Stack Overflow and Code Review, I always got some comments about my code formatting not being readable and indented even when pressing "ctrl+k".
I discussed this problem with a user in chat and he keeps telling me to click something to format my code. I forgot what it is but I remember it contains {} or something like that. However I really can't find it so I assume that is an image and he confirmed it. How can I correctly format my code here? Is there another way without clicking that image? Many questions I posted got edited because the users say my code is unreadable.
I'm using eclipse and it has a feature "correct indentation" which I think formats my code but it seems to be not working because of the edits to my codes here.
I will try @Martijn Pieters instructions. I will use a simple c++ code. I added 4 extra spaces in each line of the code.
The include directive, the main declaration and the closing brace doesn't have any spaces when I coppied from eclipse.
#include <iostream>
int main() {
int *crash = nullptr;
std::cout << *crash << std::endl;
return 0;
}
Is this correct?
edit: I made a longer code. Just to make sure I got it.
#include <iostream>
#include <string>
#include "SALES_DATA.h"
int main() {
Sales_data data1, data2;
double price = 0;
std::cin >> data1.bookNo >> data1.unitsSold >> price;
data1.revenue = data1.unitsSold*price;
std::cin >> data2.bookNo >> data2.unitsSold >> price;
data2.revenue = data2.unitsSold*price;
if (data1.bookNo == data2.bookNo) {
unsigned totalCount = data1.unitsSold+data2.unitsSold;
double totalRevenue = data1.revenue+data2.revenue;
std::cout << data1.bookNo << " " << totalCount << " " << totalRevenue << " ";
if (totalCount != 0) {
std::cout << totalRevenue/totalCount << std::endl;
} else {
std::cout << "(no sales)" << std::endl;
}
return 0;
} else {
std::cerr << "Data must refer to the same ISBN" << std::endl;
return -1;
}
}
Is this totally correct?