Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a Basic Mathmatic Program in C++
#4
All programs have the following:

Quote:#include <stdio.h>
#include <stdlib.h>

int main()
{

system("pause");
return 0;
}

To declare the identifiers you do the following:

Quote:data_type variable_name;

Example:

int a;
float b;
char c;

If you want to make a simple math equation, like adding two numbers, here's an example:

Quote:#include <stdio.h>
#include <stdlib.h>

int main()
{
int a, b, c; //declaring the variables

printf("Insert the first number: "); //asking the user to input the number
scanf("%d", &a); //saving that number on the variable "a"

printf("Insert the second number: "); //see above
scanf("%d", &b); //see above

c=a+b; //self-explanatory.

printf("The result is: %d ", c); //the user will get the answer.

system("pause");
return 0;
}
Reply


Messages In This Thread
Creating a Basic Mathmatic Program in C++ - by Conciente - 2008-07-09, 04:59 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)