#What am i doing wrong ?

40 messages ยท Page 1 of 1 (latest)

slim adder
steel merlinBOT
#

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.

slim adder
#

#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

supple raptor
slim adder
#

correct me if im wrong , im a complete begginer

#

uhm

#

XD

supple raptor
#

All format symbols start with %. Like %i for int type, %s for strings.

slim adder
#

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 @

supple raptor
#

Hmm, I realized something, yeah

slim adder
#

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");

}`

supple raptor
#

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

rapid bloom
#

In C++, use std::cout instead of printf

slim adder
#

im rly confused on the many methods of programming in c++

#

sadly i have to write it in their way

primal tinsel
#

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. ๐Ÿ™‚
slim adder
#

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 ?

primal tinsel
#

No problem! ๐Ÿ™‚

primal tinsel
#

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.

steel merlinBOT
#

@slim adder Has your question been resolved? If so, type !solved :)

slim adder
#

thank you so much for answering

#

!solved

steel merlinBOT
#

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

primal tinsel
rapid bloom