#What am i doing wrong ?
40 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
#include <stdio.h>;
#include <stdlib.h>
#include <string>
void main() {
int rows;
int columns;
char symbol;
printf("Kolko reda?: "); scanf_s("%d", &rows);
printf("Kolko koloni?: "); scanf_s("%d", &columns);
printf("Napishete simvol po vash izbor: "); scanf_s("%d", &symbol);
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= columns; j++) {
printf(symbol);
}
}
system("pause");
}
Error C2664 'int printf(const char *const ,...)': cannot convert argument 1 from 'char' to 'const char *const ' ConsoleApplication2
The printf function needs a format string as argument 1.
Example: printf("%c\n", <your variable here>)
There are other printf format symbols too, and it would be best to check online for those.
so something like this ?
printf("%c\n" , symbol);
correct me if im wrong , im a complete begginer
uhm
XD
All format symbols start with %. Like %i for int type, %s for strings.
my point is that i want to try making a square with 3 rows 6 columns with a symbol by the user's choise
like @
Hmm, I realized something, yeah
i should've writen the text in english , mb
`#include <stdio.h>;
#include <stdlib.h>
#include <string>
void main() {
int rows;
int columns;
char symbol;
printf("How many rows: "); scanf_s("%d", &rows);
printf("How many columns?: "); scanf_s("%d", &columns);
printf("Choose a symbol by your choise: "); scanf_s("%d", &symbol);
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= columns; j++) {
printf("%c\n", symbol);
}
}
system("pause");
}`
so you'll have to think of how to print each row first...
then once you got a row to print, you can go to next line with printing \n
the square is rows by columns
you have the basic loops there, but you'll need a way to print a number of char letters per row 1st
In C++, use std::cout instead of printf
thats how they explained it to us in uni
im rly confused on the many methods of programming in c++
sadly i have to write it in their way
A rule of thumb: If you import a standard library and it ends in ".h", such as with <stdio.h> and <stdlib.h> - then those are C libraries.
Whereas <string> and <iostream> (which is what includes std::cout), those are c++
One thing to try is:
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= columns; j++) {
printf("%c", symbol);
}
}```Versus what you currently have.
That combined with what DerkT said may give you the insight you need to start printing out the square.
-------
And, just as a side note on the C vs C++ thing... If you'd like to do it with the C++ library instead, then you can simply add ```cpp
#include <iostream>
``` and then replace ```cpp
printf("%c", symbol);
``` with ```c
std::cout << symbol;
``` instead. And the other `printf(<blah>);` lines generally become `std::cout << <blah>;` if you are only printing out a single value.
But if your uni wants you to use printf then go ahead and stick with that. ๐
holy fuck
this makes alot of sence
I've been asking people who program on c++ about why we use stdio.h instead of iostream , and nobody managed to give a good explenation
makes alot of sence now . Thank you so much for the clearance
btw is it an issue if i use c syntax on c++ console app ?
No problem! ๐
And, generally, no - c++ compilers will be able to compile the c++ and c parts; although it is kind of confusing to other humans to do so.
However, writing c++ and then using .c is more likely to cause problems, since c++ is much larger than c in scope.
Here is a rough picture of how the two languages compare. There is a small sliver of C that could trip up a C++ compiler, but you're unlikely to stumble upon it by accident, as they are rather niche features.
@slim adder Has your question been resolved? If so, type !solved :)
good
thank you so much for answering
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
No problem, glad I could help! Have a nice day ๐
oh my god this is a refreshing image to see. so many people blindly proclaim, with confidence, that C is a strict subset