help with variable

This is a discussion on help with variable within the C++ Programming forums, part of the General Programming Boards category; how do i get a program to display the variable i entered using the printf and scanf commands....

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    77

    Unhappy help with variable

    how do i get a program to display the variable i entered using the printf and scanf commands.

  2. #2
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    Re: help with variable

    Originally posted by jobolikescake
    how do i get a program to display the variable i entered using the printf and scanf commands.
    try this:

    PHP Code:
    #include <iostream>

    void main()
    {
      
    int i;
      
    cin >> i;
      
    cout << "The value of variable i is: " << << endl;
      
    cin >> "what";

    Never end on learning~

  3. #3
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    Location
    Egypt
    Posts
    161
    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;
    }
    Programming is a high logical enjoyable art for both programer and user !!

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680

    Re: help with variable

    Originally posted by jobolikescake
    how do i get a program to display the variable i entered using the printf and scanf commands.
    If you are programming in C++ then use cin and cout,
    otherwise use fgets and printf (try to avoid the scanf function).

    My mother always told me... scanf is bad..... very bad.

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718

    Re: Re: help with variable

    Originally posted by Monster
    [My mother always told me... scanf is bad..... very bad. [/B]
    momma's boy!!!
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    77
    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....

    thanks everyone for the help
    Hooked On Phonics Didn't Work For Me!

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    Code:
    #include <iostream.h>
    
    int main()
    {
    
    int myInt;
    cout << "enter an integer";
    cin >> myInt;
    cout << "you entered " << myInt;
    return 0;
    }
    This way it will work with cin and cout. It's very simple.
    Last edited by Zewu; 07-08-2002 at 09:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  2. Use of variable
    By alice in forum C Programming
    Replies: 8
    Last Post: 06-05-2004, 07:32 AM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 03:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21