AOA AOA AOA Folding For Team 45 AOA Files Home Front Page Become an AOA Subscriber! UserCP Calendar Memberlist FAQ Search Forum Home


Go Back   AOA > Software > Programming and Assembly Language

Programming and Assembly Language Please read this Topic's rules!!

Reply
 
LinkBack Thread Tools Rate Thread
  #1 (permalink)  
Old 25th May, 2007, 09:15 AM
Member
 
Join Date: January 2005
Location: Brighton
Posts: 4,851

Basic Stuff

Just something I'm working on at Uni. Fairly basic stuff.

Copy and paste in to Notepad and save as Filename.c (Not .txt.).

Find the file in command prompt and compile it then run it.
(Type gcc filename.c to compile, then type filename.exe to run)

Tell me what ya think so far. I'm obviously new to all this stuff so it is only a command prompt program. No GUI or anything.




Quote:
#include <stdio.h>
#include <string.h>
#include <math.h>

void option1();
void option2();
void option3();


char inputLine[100]; // Used to get inputs from the user

int main() { // Main routine


// Header Scren Variables

int option;

// Header Screen

while(option != 5)
{

printf("Please select which option you would like to execute, by pressing the corresponding number.\n\nOption 1---: Calculate the roots of quadratic equation ax^2+bx+c. Supply the values of a,b and c.\nOption 2---: Enter how many names you have. The program will print out different combinations of the full name given.\nOption 3---: Supply two integers which will then be used to calculate a*x^n.\nOption 4---: Supply a positive integer. Program will decide of integer is a power of 2. \n\n");

fgets(inputLine,sizeof(inputLine),stdin);
sscanf(inputLine,"%d",&option);

if(option==1) {
option1();
}
else if(option==2) {
option2();
}
else if(option==3) {
option3();
}
else if(option==4) {
printf("\n");
}
else if(option==5) {
printf("\n");
}

else{
printf("\n\nYou have entered an invalid option. Please try again.\n\n");
}
}


}


void option1() {

double vara;
double varb;
double varc;


printf("Please enter values for a, b and c.\n");

fgets(inputLine,sizeof(inputLine),stdin);
sscanf(inputLine, "%lf", &vara);
fgets(inputLine,sizeof(inputLine),stdin);
sscanf(inputLine, "%lf", &varb);
fgets(inputLine,sizeof(inputLine),stdin);
sscanf(inputLine, "%lf", &varc);

double result;

result = ((0 - varb) + sqrt(varb*varb - 4*vara*varc)) / 2*vara;

printf("\n%The answer is: \n",result);


}

void option2() {

char inputLine[100]; // Used to get inputs from the user
// Variables to store results in
int var1;
char firstName[100];
char surname[100];
char middlename[10][100];


printf("How many names do you have?");
fgets(inputLine,sizeof(inputLine),stdin);
sscanf(inputLine,"%d",&var1);

printf("Please enter your first name: ");
fgets(inputLine,sizeof(inputLine),stdin); // Get the input string from the user
sscanf(inputLine,"%s %s",&firstName); // Parse the input string and store the result

int i;
for(i = 0; i < (var1 - 2); i++) //loop for entering middle names
{
printf("Please enter middle name %d", i+1);
fgets(inputLine,sizeof(inputLine),stdin); // Get the input string from the user
sscanf(inputLine,"%s",&middlename[i]);
}

printf("Please enter your surname: ");
fgets(inputLine,sizeof(inputLine),stdin); // Get the input string from the user
sscanf(inputLine,"%s %s",&surname); // Parse the input string and store the result

// Output formatted sentences (firstName[0] is used to obtain the person's first initial)
printf("\nHello %s", firstName);

for(i = 0; i < (var1 - 2); i++)
{
printf(" %s", middlename[i]); //loop the result
}

printf(" %s\n\n\n", surname);

}

void option3() {

double a;
double x;
int n;


printf("Please enter values for a and x\n");
fgets(inputLine,sizeof(inputLine),stdin);
sscanf(inputLine, "%lf", &a);
fgets(inputLine,sizeof(inputLine),stdin);
sscanf(inputLine, "%lf", &x);

double result;


}




__________________


Quote:
Originally Posted by Wolf2000me
Skinny people are not petite in every aspect of the body, let me tell you that
Quote:
Originally Posted by dsio
I was searching for a synonym for testicles that rhymed with hats



E6400 - 2GB Geil Dragon Quad-Channel - X1950Pro

Exclusive Haddaway - What Is Love? Remix

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 25th May, 2007, 09:58 AM
chrisbard's Avatar
Benchmarker
 
Join Date: March 2003
Location: I turn ;)
Posts: 6,308
Send a message via MSN to chrisbard Send a message via Yahoo to chrisbard

You're doing Chinese classes?
__________________
AOA Team fah
--------------------------
Quote:
Originally Posted by Samuknow View Post
Windows 7 is very stable and faster in games. More intuitive than Vista, plus some cool stuff thrown in.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 25th May, 2007, 10:12 AM
Áedán's Avatar
Chief Systems Administrator
 
Join Date: September 2001
Location: Europe
Posts: 12,232

I think that fairly few people will have a copy of GCC on their Windows machine to compile with. You might want to consider uploading a copy of the exe file for people to play with too! (put it in a zip file)

I'm glad to see that you're using sizeof() - you'd be surprised the number of times developers forget and wonder why people exploit buffer overflows.
__________________

Last edited by Áedán; 25th May, 2007 at 10:13 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 26th May, 2007, 09:33 AM
Member
 
Join Date: January 2005
Location: Brighton
Posts: 4,851

I'll do that soon, but I need to install GCC on my PC and laptop first, as the program was compiled at University. My bad!
__________________


Quote:
Originally Posted by Wolf2000me
Skinny people are not petite in every aspect of the body, let me tell you that
Quote:
Originally Posted by dsio
I was searching for a synonym for testicles that rhymed with hats



E6400 - 2GB Geil Dragon Quad-Channel - X1950Pro

Exclusive Haddaway - What Is Love? Remix

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
basic question gazzacbr Cooling & Temperature Monitoring 2 14th March, 2005 08:06 AM
The right stuff - The wrong stuff Southern Man Random Nonsense! 0 22nd October, 2004 08:44 PM
8RDA+ basic, basic problem at boot ohhowhappy EPoX MotherBoards 2 17th January, 2003 07:28 PM


All times are GMT -5. The time now is 11:04 PM.


Copyright ©2001 - 2009, AOA Forums

Search Engine Friendly URLs by vBSEO 3.3.0