-
Error count exceeds 100
Hey all,
I started creating my first C program to test my comprehension of the basics, but I'm running into over 100 syntax errors. I can't tell what I'm doing wrong. Here's the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath.h>
void mainmenu();
int joke();
int calculator();
int addition();
int subtraction();
int multiplication();
int division();
int add ( int x, int y );
int subtract ( int x, int y );
int multiply ( int x, int y );
int divide ( int x, int y );
int main()
{
system ("cls");
printf("Hello. Welcome to the program.\n");
printf("Press any key to continue...\n");
getchar();
mainmenu();
}
void mainmenu()
{
int menu1choice;
printf("Menu 1\n");
printf("~~~~~~~~~~\n");
printf("1. Tell me a joke.\n");
printf("2. Perform a simple calculation.\n");
printf("3. Move to Menu 2.\n");
scanf("%d", &menu1choice);
switch ( menu1choice ) {
case 1:{
joke();
break;
}
case 2:{
calculator();
break;
}
}
}
}
int joke()
{
system("cls");
printf("How do you get holy water? \n");
system("pause");
printf("You boil the hell out of it. \n");
system("pause");
system("cls");
mainmenu();
}
int calculator()
{
int calculatorchoice;
system("cls");
printf("What type of calculation would you like to make? \n");
printf("1. Addition \n");
printf("2. Subtraction \n");
printf("3. Multiplication \n");
printf("4. Division \n");
scanf("%d", &calculatorchoice);
switch ( calculatorchoice ){
case 1:{
addition();
break;
}
case 2:{
subtraction();
break;
}
case 3:{
multiplication();
break;
}
case 4:{
division();
break;
}
}
}
int addition()
{
int x;
int y;
system("cls");
printf("Please input two numbers to be added: ");
scanf( "%d", &x );
scanf( "%d", &y );
printf( "The product of your two numbers is %d\n", add( x, y ) );
getchar();
}
Any help is appreciated
-
Remove this line as there is usually no sense in including a C++ header in a C program:
Code:
#include <iostream>
Change this line:
to:
You may still have more syntax errors, but don't worry about the count: fix them one by one.
-
-
In addition to that, you've got an extra "}" on mainmenu, all the calculating functions but addition aren't defined (and produce linker errors), and you're not returning anything from functions that are supposed to return ints.
-
You just couldn't settle for a Hello World eh?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void mainmenu();
int joke();
int calculator();
int addition();
int add ( int x, int y );
/* Noted out temporarily because these functions are not yet created.
int subtraction();
int multiplication();
int division();
int subtract ( int x, int y );
int multiply ( int x, int y );
int divide ( int x, int y );
*/
int main()
{
system ("cls");
printf("Hello. Welcome to the program.\n");
printf("Press any key to continue...\n");
getchar();
mainmenu();
}
void mainmenu()
{
int menu1choice;
system("cls");
printf("Menu 1\n");
printf("~~~~~~~~~~\n");
printf("1. Tell me a joke.\n");
printf("2. Perform a simple calculation.\n");
printf("3. Move to Menu 2.\n");
scanf("%d", &menu1choice);
switch ( menu1choice ) {
case 1:{
joke();
break;
}
case 2:{
calculator();
break;
}
}
}
int joke()
{
system("cls");
printf("How do you get holy water? \n");
system("pause");
printf("You boil the hell out of it. \n");
system("pause");
system("cls");
mainmenu();
}
int calculator()
{
int calculatorchoice;
system("cls");
printf("What type of calculation would you like to make? \n");
printf("1. Addition \n");
printf("2. Subtraction \n");
printf("3. Multiplication \n");
printf("4. Division \n");
scanf("%d", &calculatorchoice);
switch ( calculatorchoice ){
case 1:{
addition();
break;
}
/* Noted off because cases call functions that do not exist yet.
case 2:{
subtraction();
break;
}
case 3:{
multiplication();
break;
}
case 4:{
division();
break;
}*/
}
}
int addition()
{
int x;
int y;
system("cls");
printf("Please input two numbers to be added: ");
scanf( "%d", &x );
scanf( "%d", &y );
printf( "The product of your two numbers is %d\n", add( x, y ) );
getchar();
}
int add(num1,num2)
{}
This compiles, but a good practice is to add a function, compile, debug, repeat. That way you don't run into 20 compiler errors. By the way, you had an extra
Code:
} //made me put code tags around this -_-
in your main menu. This is most often caused by poor indentation practices.
EDIT: Memcpy, you beat me to that.
* Proper indentation is encouraged for all programming languages.
* It shows levels of nesting, nested if statements , for loops, etc.
* Anyone reading your code can tell whats executing inside of what.
* It shows scope. If everything is indented you know the scope of variables.
* Easier to read.
* Better programming sense.
Suggested reading:
http://cboard.cprogramming.com/c-pro...t-process.html