How to start C Programing with Dev C++

C, C++, Visual C++, C++.Net Topics
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Tue Nov 09, 2010 10:34 pm

Code: Select all

//My fourth programm in C++
#include<iostream>
using namespace std;
int main()
{
    int x,y;
    char name;
    cout<<"Please enter you name :- "<<endl;
    cin>>name;
    cout<<"hello "<<name;
    cout<<"we are going to test addition"<<endl;
    cout<<"Please enter a number 1 = "<<endl;
    cin>>x;
    cout<<"Please enter a number 2 = "<<endl;
    cin>>y;
    cout<<"number 1 + number 2 = "<<x+y<<endl;
    system("pause");
    
    
    }
Can you give me a help to make these errors.
1.I wanna get the user name.That's why I used variable as "name" & wanna get the print out as "hello ............."(ex-hello g-sparkz)
2.then I wanna run my adding system.

Errors-
  1. I get user in put window,I can enter a name also.But Don't get any name out put in "hello .........."line.Just one letter disply.
  2. code run with out errors when I compile.But not working properly after entering the name.it don't ask for any number input.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to start C Programing with Dev C++

Post by Neo » Tue Nov 09, 2010 11:09 pm

I changed the code a bit. Note the spaces I have added within lines to make the code clear. And the tab (indents) I put before every line. These are very important to maintain in programming.

Regarding the name input.... the problem you had was you were trying to get the input to a char. char can only holds a single character. But here you enter a set of characters. So you will have to use a char array here. I assumed you would not enter a name with more than 50 characters.

There is no requirement to use a int main since you do not output anything. So void main is enough.

Code: Select all

//My fourth programm in C++
#include<iostream>


using namespace std;



void main()
{

	int x,y;
	char name[50];


	cout << "Please enter you name :- ";

	cin >> name;

	cout << "hello " << name << endl << endl;


	cout << "we are going to test addition" << endl;
	cout << "Please enter a number 1 = ";
	cin >> x;

	cout << endl << "Please enter a number 2 = ";
	cin >> y;

	cout << endl << "number 1 + number 2 = " << x+y << endl;

	system("pause");

	return;
}
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: How to start C Programing with Dev C++

Post by Nipuna » Wed Nov 10, 2010 9:14 am

Neo Buddy I am Not Clear with this.
There is no requirement to use a int main since you do not output anything. So void main is enough.
Because we are out putting via

Code: Select all

cout <<
Thanks
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to start C Programing with Dev C++

Post by Neo » Wed Nov 10, 2010 12:01 pm

Neo Buddy I am Not Clear with this.

There is no requirement to use a int main since you do not output anything. So void main is enough.
I mean outputting something (by return value) to the calling programme. As long as there is no special requirement for you to use something like return 5;, always use void in front of functions including main.

For example:

Code: Select all

int sum(int a, int b){
     return (a+b);
}

void main(){
      count << sum (21+ 34);
}
See we use int sum(), just because we return something to the calling function. But we use void main(), since there is no requirement to return anything from there.
Because we are out putting via
cout <<
From cout, printf, etc... we write to stdout (Standard output). This is the display.
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: How to start C Programing with Dev C++

Post by Nipuna » Wed Nov 10, 2010 7:28 pm

Now I understand a Little. I think I have so much to learn to Understand these All :)
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Thu Nov 11, 2010 6:11 pm

Code: Select all

    //My fourth programm in C++

    #include<iostream>

    using namespace std;
    int main()
    {
        int x,y;
        char name[50];

        cout<<"Please enter you name :- "<<endl;

        cin>>name;
        cout<<"hello "<<name;

        cout<<"we are going to test addition"<<endl;

        cout<<"Please enter a number 1 = "<<endl;
        cin>>x;

        cout<<"Please enter a number 2 = "<<endl;
        cin>>y;

        cout<<"number 1 + number 2 = "<<x+y<<endl;
        system("pause");
       
       
        }
NEO thanks buddy.I love programming.thanks for your great help.I will try to make another today & will post it here.
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Thu Nov 11, 2010 6:49 pm

Neo Buddy,I wanna make some changes in my little program.Here it is,

Code: Select all

//G-sparkz little billing Pack

#include<iostream>

using namespace std;

int main()
{
    int Paper,Quantity,Total;
    char Name[50];
    
    cout<<"Welcome to G-sparkZ Billing Pack"<<endl<<endl;
    
    cout<<"Please enter your name"<<endl;
    cin>>Name;
    cout<<Name <<" entered the G-SparkZ Billing system "<<endl<<endl;
    
    cout<<"Enter your paper size ";
    cin>>Paper;
    
    cout<<"How many pages ";
    cin>>Quantity;
    
    cout<<"paper - "<<Paper<< " Pages - "<< Quantity<<endl;
    
    Total=Paper*Quantity;
    
    cout<<"Total price - "<<Total<<endl;
    
    system("pause");
    }
1.I wanna get some line after entering paper size & Pages.
2.I wanna define some paper sizes & give values for them.

Can you help me to make lines.I will ask my second question after thing what are the values I wanna assign.I have not designed it yet.
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: How to start C Programing with Dev C++

Post by Nipuna » Thu Nov 11, 2010 7:20 pm

I think adding Like this would work

Code: Select all

paper = 4;
Like that. I don't know exactly
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: How to start C Programing with Dev C++

Post by Face » Thu Nov 11, 2010 7:29 pm

Thanks for your attention NIPUNA.I wanna make some lines first.Then I will try to get user inputs.I started new topic for this.Because this is getting bigger & bigger. ;)
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: How to start C Programing with Dev C++

Post by SemiconductorCat » Mon Aug 22, 2011 10:00 pm

my WELL EXPERIENCED BIG BOSS told me that DEV C++ is too old and deprecated. So
use Code Blocks or Code Lite.(he told me not me).
Post Reply

Return to “C/C++ Programming”