Stored data gets corrupted in C - c

i'm learning myself programming in c witch basicly no previous programming experience and now i have a weird bug and would like to ask some advice.
In the program flow some of the input data gets suddenly changed and i can't see nor reason why that happens.
1.program starts -> user gets a menu choice -> selects case 1 -> program provides and additional input posiblity.... So far everything works correctly as i could see in debug mode.
2.The user puts in some numbers and the variable gets set to that number.
(this happens in input.c)
3.Then the program continues in main.c to info_bottom().
(in circlemenu.c)
4.In there the function getRadius() gets called that should calculate a radius based on the user input set in input.c in point 2.
5.That calculation function is located in circlefunctions.c
But here/there is the strange thing.
If i look in the debugger, i see that the variable diameter and radius are both changed to some weird numbers and not the number that the user specified in point 2.
Somehow the data stored in the pointer gets corrupted as far as i can judge.
Unfortunately im still to inexperienced with debugging to find this out on my own so hopefully someone can please tell me what is going on.
This problem occured while trying to get rid of all global variables in my program.
Im beginning to get a whole new respect and understanding for professional programmers and why it can take so long sometimes to fix bugs o0.
(i also made the corresponding header files but no need to put them up i think?)
main.c
#include <stdio.h>
#include "menu/menu.h"
#include "circle/circlemenu.h"
#include "input/input.h"
int main(void)
{
while(1)
{
menu();
switch(menu_user_input())
{
case 1:
info_top();
cir_user_input();
info_bottom();
break;
case 2:
system("cls");
break;
case 3:
system("cls");
break;
case 8:
system("cls");
break;
case 9:
system("cls");
break;
case 0:
return(0);
default:
system("cls");
printf("\n **Wrong choice try again...**\n");
break;
}
}
return 0;
}
menu.c
#include <stdio.h>
#include "menu.h"
void menu()
{
printf(" \n Made by ************* 2015.\n");
printf(" ----------------------------------------\n\n");
printf(" 1. Calculate circle measurements. \n");
printf(" 2. \n");
printf(" 3. \n");
printf(" 8. Info. \n");
printf(" 9. Clear screen. \n");
printf(" 0. Exit. \n \n");
printf(" Make your choice and press enter: ");
}
input.c
#include <stdio.h>
#include "input.h"
int menu_user_input()
{
static int number;
scanf(" %i", &number);
return number;
}
float cir_user_input()
{
static float diameter;
scanf("%f", &diameter);
return diameter;
}
circlemenu.c
#include <stdio.h>
#include "circlemenu.h"
#include "circlefunctions.h"
void info_top()
{
system("cls");
printf(" ----------------------------------------\n");
printf(" Typ the diameter of the circle: ");
return;
}
void info_bottom()
{
printf(" ----------------------------------------\n");
printf(" The radius = %f \n\n" , getRadius());
printf(" The surface = %f \n\n" , getSurface());
printf(" The outline = %f \n" , getOutline());
printf(" ----------------------------------------\n");
return;
}
circlefunctions.c
#include "circlefunctions.h"
#include "../input/input.h"
#define PI 3.14
double getRadius()
{
static diameter = (*cir_user_input);
double radius = diameter / 2;
return radius;
}
double getSurface()
{
double radius = getRadius();
return PI * (radius * radius);
}
double getOutline(){
double radius = getRadius();
return 2 * PI * radius;
}

You are using your cir_user_input in your getRadiusfunction like a variable/pointer, although it is a function. It is surprising that this works without any warnings or errors (would be interesting to know what compiler you are using).
I think what you actually intended was something like this, i.e., a call to cir_user_input which stores the result in a float variable.
double getRadius()
{
float diameter = cir_user_input(); //float type; not static (see below)
double radius = diameter / 2;
return radius;
}
Furthermore, the switch statement in your main function only calls the user input function cir_user_input, but none of the calculation routines (case 1). Since the return value of the function is not store, it cannot be used later.
In addition, you have seem to be confused about the use of the static key word:
This problem occured while trying to get rid of all global variables in my program.
When you use the static key word to declare variables inside a function, they retain their values throughout function calls, i.e., they are effectively global.
Conversely, if you use the static key word for a global variable/function etc., it is only visible inside the file you specified it in. For beginners, this is often confusing since the key word is written in exactly the same way, see What does "static" mean?.
Best regards
Andreas

here is a good implementation of the main() function
#include <stdio.h>
#include "menu/menu.h"
#include "circle/circlemenu.h"
#include "input/input.h"
int main(void)
{
int done = 0;
while( !done )
{
menu();
switch(menu_user_input())
{
case 0:
done = 1;
break;
case 1:
info_top();
cir_user_input();
info_bottom();
break;
case 2:
system("cls");
break;
case 3:
system("cls");
break;
case 8:
system("cls");
break;
case 9:
system("cls");
break;
default:
system("cls");
printf("\n **Wrong choice try again...**\n");
break;
} // end switch
} // end while
return 0;
} // end function: main

Related

C code Calculations not outputting correctly after adding exit for program

Hey guys n gals first time poster first time learning code.
I am sure I am missing something very small that comes naturally when you stare at code long enough. Why are my calculations not working? what am I missing ?
I can get it working without implelemting the # exit but im sure im missing something here.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char input;
int a,b,c;
while(1) {
printf("\nPlease Enter Temperature in kelvin \n\nThen enter # when you have had enough:\n ");
scanf(" %c", &input);
if(input == '#'){
break;
}
if(input != '#') {
scanf("%d",&c);
printf("\n1.Convert to celcius\n2.Convert to fahrenheit\nEnter choice now\n");
scanf("%d",&a);
switch(a) {
case 1:
b=(c-273);
printf("Temperature in celcius is %d\n\n",b);
break;
case 2:
b=((c*9)/5)-460;
printf("Temperature in fahrenheit is %d\n\n",b);
break;
default:
printf("You selected wrong choice");
break; /// End of code here
}
}
getchar ();
}
return 0;
}
the following proposed code:
appropriately horizontal spaced
appropriately vertically spaced
includes the suggested changes from the comments to the question
displays how to cleanly display menu
displays how to honor the right margin (column 72 or 80)
replaces 'magic' numbers with meaningful names
and now, the proposed code:
#include <stdio.h>
#include <stdlib.h>
#define CONVERT_KEVIN_TO_CELCIUS 273
#define OFFSET_KEVIN_TO_FAREN 460
int main( void )
{
char input;
int a,b,c;
while(1)
{
printf("%s",
"\nPlease Enter Temperature in kelvin"
"\n\nThen enter # when you have had enough:\n");
scanf(" %c", &input);
if(input == '#')
{
break;
}
ungetc( c, stdin );
scanf("%d",&c);
printf("%s",
"\n1.Convert to celcius"
"\n2.Convert to fahrenheit"
"\nEnter choice now\n");
scanf("%d",&a);
switch(a)
{
case 1:
b=(c-CONVERT_KEVIN_TO_CELCIUS);
printf("Temperature in celcius is %d\n\n",b);
break;
case 2:
b=((c*9)/5)-OFFSET_KEVIN_TO_FAREN;
printf("Temperature in fahrenheit is %d\n\n",b);
break;
default:
printf("You selected wrong choice");
break;
}
}
getchar ();
return 0;
}
Why are my calculations not working?
Code has various technical problem well addressed elsewhere.
Thought I'd mention some numeric issues.
To convert K to °F:
°C = 0K − 273.15
°F = °C×9/5 + 32
To do so with integer math and get the best answer
// (K − 273.15)×9/5 + 32
// (K*100 − 27315)×9/(5*100) + 32
// ((K*100 − 27315)×9 + 32×500)/500
// ((K*100 − 27315)×18 + 32×1000)/1000
// above using real math, below using integer C math
// t = (K*100 − 27315)×18 + 32×1000; (t + signof(t)*500)/1000
// More simplifications possible
int t = (K*100 - 27315) * 18 + 32*1000;
t += (t < 0) ? -500 : 500; // round by adding half the divisor, correctly signed
F = t/1000;
To do so with FP math and get a good integer answer
#include <math.h>
F = lround((K − 273.15)*9.0/5.0 + 32);

How to debug a C program producing unexpected output?

I am new to programming C and I don't know why my program is not printing the desired output.
#include <stdio.h>
void main(void)
{
char res,res1;
float money=10;
printf("***Wealcome to Peace of Mind***");
printf("\nHello we have the menu please check::");
printf("\n***Menú***");
printf("\n");
printf("\n<<<Bebidas>>>");
printf("\n 1 - Coca-Cola = 1,5 2 - IceTea = 1,4");
printf("\n 3 - Super Bock = 1,70 4 - Sumol = 1,6");
printf("\n");
scanf("%d",&res);
switch(res)
{
case 1 || 'Coca-Cola':money - CocaCola;break;
}
printf("%.1f",money);
//Is that result i want:
printf("\n%.1f",10-1.5);
}
Output of my program:
The syntax of your case statement is not correct. Also the code is using scanf() to read an integer, but storing the integer-sized value in a char.
I tidied up the code:
#include <stdio.h>
int main(void)
{
int res;
float cost = 0;
float money = 10;
printf("***Wealcome to Peace of Mind***\n");
printf("Hello we have the menu please check::\n");
printf("***Menú***\n");
printf("\n");
printf("<<<Bebidas>>>\n");
printf(" 1 - Coca-Cola = 1,5 2 - IceTea = 1,4\n");
printf(" 3 - Super Bock = 1,70 4 - Sumol = 1,6\n");
printf("\n");
scanf("%d", &res);
switch(res)
{
case 1:
cost = 1.5;
break;
case 2:
cost = 1.4;
break;
// TODO: case 3 & 4
default:
printf("Invalid Entry\n");
cost = 0;
}
printf("money = %.1f\n", money - cost);
return 0;
}
Some further notes:
As commentators pointed out, put \n at the end of the string
When you compile, turn on warnings, and try to fix all of them.
In case blocks, it's good practice to have a default to catch errors
It would be worthwhile to store the drink prices as #define constants (or as an array of values, or some common area so the value is only set once in the program, and everything else just references that.)
#define COLA_COST 1.5

the loop in magic 8 ball has a bug

I'm trying to make a Magic 8 Ball program but my loop has a bug.
If you play again, the loop messes up and behaves like you were hitting enter all the time for about three cycles until it will work again.
Also, there is a delay when you enter you question. You have to hit enter twice to get the answer.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
void ans(int x);
int main()
{
system("color 0A");
srand(time(0));
int num,i;
do{
char question[100] = {" "};
num = rand()%10;
puts("MAGIC 8 BALL!");
puts("Press Enter When Ready.");
getch();
system("cls");
puts("Input Yes or No questions only!");
printf("\n");
scanf("%s",&question);
getch();
printf("\nTHE ANSWER | ");
ans(num);
getch();
system("cls");
printf("Press any key to try again.\nPress [x] to Exit.");
if(getch()=='x'){
system("cls");
break;
}
system("cls");
}while(1);
}
void ans(int x){
switch(x){
case 1 : printf("YES!");break;
case 2 : printf("NO!");break;
case 3 : printf("It's a thumbs down.");break;
case 4 : printf("Positive!");break;
case 5 : printf("As I see it Yes.");break;
case 6 : printf("Certainly!");break;
case 7 : printf("Negative!");break;
case 8 : printf("Don't Count on it.");break;
case 9 : printf("You don't want to know, trust me.");break;
case 10: printf("I can't say right now.");break;
default : printf("Cannot be determined right now");break;
}
}
Fixed your problem. Added comments explaining. Hopefully I caught everything. Tested the program, and it works fine now.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <string.h>
//#include <unistd.h>
#define MAX_QUESTION 1000
#define STATEMENT_AMOUNT 10
int random_num_generator();
void statement_picker(int x);
int main(void) {
char temp;
int rand;
// Your while condition really just needs to be scanning 1 character.
// No point in scanning the entire string, because we don't even use the string
// The scanning jus tells us when to start the loop again
while (1) {
// The introduction of our program
system("cls");
printf("MAGIC 8 BALL!\n");
printf("Press Enter When Ready.\n");
getch();
// Asking user to enter in their question
system("cls");
printf("What is your question?\n");
printf("Only enter yes or no questions!\n");
// You have to flush (aka clear) stdin. Because it uses your previous inputs
// automatically. For example, if you type "I am the best?". The program will not work
// properly for num_of_words - 1 iterations. So 4 - 1. Will not work properly for
// 3 iterations
// Also you don't need to scan in the word, because we don't really care what question
// the user typed. You can save some memory by only scanning in a single character.
// We only use scanf to give a real magic 8 ball experience by stopping and waiting
// for the user to type their question.
scanf("%c", &temp);
fflush(stdin);
// Generating a random number
printf("The answer you seek: ");
rand = random_num_generator();
statement_picker(rand);
// So I noticed here you cls, but you cls without waiting. This the user won't
// be able to read your answer in time. So you should cls after you ask the user
// to quit, or have a timer. Commented a timber for you below. You also need to
// include the unistd.h library to use the sleep function. Just uncomment it
// in the #includes section if you want the timer.
// sleep(10);
// system("cls");
// Asking the user if they want to try again
printf("Would you like to ask another question?\n");
printf("Press [x] to quit\n");
printf("Press any other character to continue\n");
scanf("%c", &temp);
if (temp == 'x') break;
// Flush at the end too, just in case the person types multiple things rather than
// one characters
fflush(stdin);
}
system("cls");
return 0;
}
// Generates a random number between 0 - 10.
/* I noticed in your switch statement you start at case 1. You should start at case 0,
* because you are using the modulus operator Just for example, if rand generators 30 and
* you have 10 cases you will be doing (30 % 10) which is equal to 0 because 10 goes into 10,
* 3 times with no remainders If you really want to start your switch case at 1,
* then you have to plus one to the return value in random_num_generator
*/
int random_num_generator() {
time_t t;
srand((unsigned) time(&t));
return rand() % STATEMENT_AMOUNT;
}
// Picks a statement and prints it, depending on the value of x
void statement_picker(int x){
switch(x){
// Your case should start at 0, not 1 because you will never print out case 0
// the way you had it before.
case 0 : printf("YES!\n");break;
case 1 : printf("NO!\n");break;
case 2 : printf("It's a thumbs down.\n");break;
case 3 : printf("Positive!\n");break;
case 4 : printf("As I see it Yes.\n");break;
case 5 : printf("Certainly!\n");break;
case 6 : printf("Negative!\n");break;
case 7 : printf("Don't Count on it.\n");break;
case 8 : printf("You don't want to know, trust me.\n");break;
case 9 : printf("I can't say right now.\n");break;
// No need for default because you'll never get to it
// (just because of how we implemented this software)
// default : printf("Cannot be determined right now");break;
}
}
You may try this
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void ans(int x);
int main()
{
srand(time(0));
int num,i;
do{
num = rand()%10;
char question[1000];
puts("MAGIC 8 BALL!");
puts("Press Enter When Ready.");
puts("Input Yes or No questions only!\n");
scanf("%s",question);
printf("\nTHE ANSWER | ");
ans(num);
printf("\n\n");
printf("Press any key to try again.\nPress [x] to Exit.\n\n");
char c = getchar();
c=getchar();
if(c=='x'){
break;
}
}while(1);
}
void ans(int x){
switch(x){
case 1 : printf("YES!");break;
case 2 : printf("NO!");break;
case 3 : printf("It's a thumbs down.");break;
case 4 : printf("Positive!");break;
case 5 : printf("As I see it Yes.");break;
case 6 : printf("Certainly!");break;
case 7 : printf("Negative!");break;
case 8 : printf("Don't Count on it.");break;
case 9 : printf("You don't want to know, trust me.");break;
case 10: printf("I can't say right now.");break;
default : printf("Cannot be determined right now");break;
}
}

How to keep track of the amount a certain loop has run and storing values into arrays

I am a newbie in coding and preparing an assignment in which I am encountering certain difficulties. I just want you guys to help me identify my mistake for one issue I am facing. Before pasting my code I am giving an overview of what had to be done.
The user have to create drones and after creating one drone the program should return back to the main menu, store the details of the 1st drone and if request to enter another drone he/she should be allowed to do so until the number of drones have reached 10. Only 10 drones are allowed and we have to use arrays for storing the values of each drone. I am unable to make the program count 10 and using arrays to store them. In the code I have pasted here, I am trying for 2 but I am unable to do that as well. Please help me...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct drone_t{
char name[30];
float top_s;
float acc;
};
void printing (struct drone_t dron[2]);
int main()
{
int a, i;
char nam;
struct drone_t drone[2];
printf("Welcome to the drone travel time calculator\n");
printf("1. Create Drone\n2. Calculate Time\n3. Exit\n");
scanf("%d", &i);
if (i == 1)
{
for (a=1; a < 3; a++)
{
printf("What is the name of the drone?\n");
scanf("%s", drone[a].name);
printf("What is the top speed of the drone? (kmph)\n");
scanf("%f", &drone[a].top_s);
printf("What is the acceleration of the drone? (mpsps)\n");
scanf("%f", &drone[a].acc);
printing(drone);
}
}
else if (i == 2)
{
printing(drone);
}
}
void printing (struct drone_t dron[2])
{
int a;
for (a=1; a < 3; a++)
{
printf("Name is: %s\n", dron[a].name);
}
//return 0;
}
Anticipated Output is:
Welcome to the drone travel time calculator
1. Create Drone
2. Calculate Time
3. Exit
1
What is the name of the drone?
Jayne
What is the top speed of the drone? (kmph)
12
what is the acceleration of the drone? (mpsps)
12
1. Create Drone
2. Calculate Time
3. Exit
1
What is the name of the drone?
JayneW
What is the top speed of the drone? (kmph)
12
what is the acceleration of the drone? (mpsps)
12
1. Create Drone
2. Calculate Time
3. Exit
2
Select a drone:
1. Jayne
2. JayneW
EDIT:
#coderredoc
Here is the full code.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
struct drone_t{
char name[30];
float top_s;
float acc;
};
void show_menu();
void do_create(int dronesCreated);
#define MAXDRONES 10
int main()
{
int dronesCreated = 0;
int i;
while(1)
{
show_menu();
if (i == 1)
{
if(dronesCreated<=MAXDRONES-1)
{
dronesCreated++;
do_create(dronesCreated);
}
else
{
printf("error: cannot create more drones");
}
}
else
{
break;
}
}
}
void show_menu()
{
int i;
printf("1. Create Drone\n2. Calculate Time\n3. Exit\n");
scanf("%d", &i);
}
void do_create(int dronesCreated)
{
char name[10];
int b, c;
int count = dronesCreated;
struct drone_t drone[10];
for (b=0; b <= count; b++)
{
printf("What is the name of the drone?\n");
scanf("%s", drone[b].name);
printf("What is the top speed of the drone? (kmph)\n");
scanf("%f", &drone[b].top_s);
printf("What is the acceleration of the drone? (mpsps)\n");
scanf("%f", &drone[b].acc);
}
}
As far as I can understand you are stuck in this part.
How to continue getting input?
For that you need to write a while(1){..} with a propr exit condition like break etc.
Rest of the job boils down to how many drones are there? and accessing and storing them.
For storing an array of structure will be sufficient. For count of drone you can use a seperate variable. Accessing them is nothing but array access.
A pseudocode to your guide:
#define MAXDRONES 10
int dronesCreated =0;
while(1){
show _menu();
if( option is DRONE_CREATE){
if(dronesCreated<=MAXDRONES-1){
do_create();//increment NUM_OF_DRONES here.
dronesCreated++;
}
else
print appropriate message.
else if(option is PRINT)
print()
else
break;
}
Look it is simple to understand the design of the program from intuitive viewpoint.
You need a loop because you need to continuouskly ask for option from user. That's why loop.
How to stop at 10 drones?
You keep a variable and check when DRONE_CREATE option is given whether 10 drones are created. If yes then don't call the function else do call the function.
Implementation centric approach:
Now as you are using the global array of structures for the drones, you need to use a count varible like this.
int numberOfDrones = 0; And then use the control as shown above.
How to print and scan the drones?
Simply the way you would input and output them.
scanf("%s",drone[a].name);
print("%s,%d",drone[a].name,drone[a].age);
All at one time:
for(int i=0;i<MAXDRONES;i++){
printf("What is the name of the drone?\n");
scanf("%s", drone[a].name);
printf("What is the top speed of the drone? (kmph)\n");
scanf("%f", &drone[a].top_s);
printf("What is the acceleration of the drone? (mpsps)\n");
scanf("%f", &drone[a].acc);
printing(drone);
}
You have a fundamental error that catches many people new to C-like languages:
Array subscripts in C run from zero, i.e. the first element of array drone would be "drone[0]".
This means that when your code executes the main() for loop for the second time it will be writing the data outside the bounds of the array. This results in undefined behaviour. The quick fix is to change the for loop to: for (a=0; a < 2; a++) in both main() and printing().
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DRONES 10
struct drone_t{
char name[30];
float top_s;
float acc;
};
void printing (struct drone_t dron[]); //no need to mention size while prototyping
int main()
{
unsigned short cnt,choice;
//char nam; //uneccessary variable
struct drone_t drone[DRONES];
printf("Welcome to the drone travel time calculator\n");
do{
printf("1. Create Drone\n2. Calculate Time\n3. Exit\n:\t");
scanf("%d", &choice);
switch(choice)
{
case 1:
for (cnt=0; cnt < DRONES; cnt++)
{
printf("What is the name of the drone?\n");
scanf("%s",drone[cnt].name);
printf("What is the top speed of the drone?(kmph)\n");
scanf("%f", &drone[cnt].top_s);
printf("What is the acceleration of the drone?(mpsps)\n");
scanf("%f", &drone[cnt].acc);
}
printing(drone);//put this statement outside loop
break;
case 2:
printing(drone);
break;
case 3:
exit(EXIT_SUCCESS);
default:
printf("choose correct option :D");
break;
}
}while(choice!=3); //if explicitly using exit case then not needed
}
void printing (struct drone_t dron[10])
{
unsigned short cnt;
for (cnt=0; cnt < DRONES; cnt++)
{
printf("Name is: %s\n", dron[cnt].name);
}
}
Note: Don't use for(cnt=1;;) it may cause problems like an off-by-one error so better use for(cnt=0;;).

Bug in calculation function / program flow in C

I have made a verry simple calculation prog to teach myself C. but i have an odd bug now and would like to ask some advice.
About an hour ago i also asked help here to get rid of global variables and got some suggestions (again thanks for that).
Now i have implemented those suggestions but when i now input a diameter in the calculation it returns with a verry large and odd number for al 3 functions.
And that number is the same for all 3 functions.
I don't understand where the function is getting that number from as i define the diameter variable in the cir_user_input() (input.c) first and only call it again in getRadius(float diameter) (circlefunctions.c). i have tried several things like pointers or make use of the EXTERN statement but that did not gave me the result that i wanted/expected. Hopefully someone can point me out on what i do wrong here or can suggest some documentation on how to solve this?
main.c
#include <stdio.h>
#include "menu/menu.h"
#include "circle/circlemenu.h"
#include "input/input.h"
int main(void)
{
while(1)
{
menu();
switch(menu_user_input())
{
case 1:
info_top();
cir_user_input();
info_bottom();
break;
case 2:
system("cls");
break;
case 3:
system("cls");
break;
case 8:
system("cls");
break;
case 9:
system("cls");
break;
case 0:
return(0);
default:
system("cls");
printf("\n **Wrong choice try again...**\n");
break;
}
}
return 0;
}
circlemenu.c
#include <stdio.h>
#include "circlemenu.h"
void info_top()
{
system("cls");
printf(" ----------------------------------------\n");
printf(" Typ the diameter of the circle: ");
}
void info_bottom(double diameter)
{
printf(" ----------------------------------------\n");
printf(" The radius = %f \n\n" , getRadius(diameter));
printf(" The surface = %f \n\n" , getSurface(diameter));
printf(" The outline = %f \n" , getOutline(diameter));
printf(" ----------------------------------------\n");
}
circlefunctions.c
#include "circlefunctions.h"
#include "../input/input.h"
#define PI 3.14
double getRadius(float diameter)
{
double radius = diameter / 2;
return radius;
}
double getSurface(float diameter){
double radius = getRadius(diameter);
return PI * (radius * radius);
}
double getOutline(float diameter){
double radius = getRadius(diameter);
return 2 * PI * radius;
}
input.c
#include <stdio.h>
#include "input.h"
int menu_user_input()
{
int number;
scanf(" %d", &number);
return number;
}
float cir_user_input()
{
float diameter;
scanf(" %e", &diameter);
return diameter;
}
edit
I forgot to mention that im verry new to programming and im just trying to learn it myself. Some things may seem to be odd but im just trying to tackle and understand one problem at the time.
info_bottom(); you should pass diameter as argument i.e. info_bottom(diameter);
Adding to #JerryGoyal 's answer, In your main.c
case 1:
info_top();
cir_user_input();
info_bottom(); // here
break;
In the commented line, you need to give info_bottom() an argument when you call it. Something like info_bottom( diameter ); where diameter is a variable of type double you must declare in your main.c
If you had your compiler Warnings turned on, it should have warned you about this.
You should also make the diameter in
double getRadius(float diameter)
double getSurface(float diameter)
and
double getOutline(float diameter)
of type double. In other words, the arguments should be double diameter

Resources