how do i get a program to display the variable i entered using the printf and scanf commands.
Printable View
how do i get a program to display the variable i entered using the printf and scanf commands.
try this: :)Quote:
Originally posted by jobolikescake
how do i get a program to display the variable i entered using the printf and scanf commands.
PHP Code:
#include <iostream>
void main()
{
int i;
cin >> i;
cout << "The value of variable i is: " << i << endl;
cin >> "what";
}
here its using scanf(), printf()
Code:
include <stdio.h>
int main(){
int myInt;
printf("enter an integer");
scanf("%d",&myInt);
printf("you entered %d",myInt);
return 0;
}
If you are programming in C++ then use cin and cout,Quote:
Originally posted by jobolikescake
how do i get a program to display the variable i entered using the printf and scanf commands.
otherwise use fgets and printf (try to avoid the scanf function).
My mother always told me... scanf is bad..... very bad.
momma's boy!!! :DQuote:
Originally posted by Monster
[My mother always told me... scanf is bad..... very bad. [/B]
i tried using the cout and cin but iostream.h for some reason produces anywhere from 3-33 errors so i just gave up on it, but i did get my program to work using the way moemen explained so im happy now....:D
thanks everyone for the help
This way it will work with cin and cout. It's very simple.Code:#include <iostream.h>
int main()
{
int myInt;
cout << "enter an integer";
cin >> myInt;
cout << "you entered " << myInt;
return 0;
}