I am getting all sorts of incorrect type warnings when I compile the following code:
// hw1.c
// Josh Soileau
// 1/19/10
// Program: Asks / stores info on a bank
//
#include<stdio.h>
int main(){
char name[25] = "blank", rating[25] = "blank", state[25] = "blank";
int lobbyists=0, prevemploys=0, number=0;
double networth=0, tarp=0, contributions=0;
printf("\n\n(1)Bank name: %s\n(2)State: %d\n(3)Net worth: %d\n", name, state, networth);
printf("(4)Rating: %s\n(5)TARP money: %d\n(6)Campaign contributions: %d\n", rating, tarp, contributions);
printf("(7)Lobbyists in capitol: %d\n(8)Previous Employees in government: %d\n", lobbyists, prevemploys);
printf("\n(9)Display Data\n(10)Clear all Data\n(11)Quit\n\n");
while (number != 11){
printf("Type the number to edit the field / perform task, and press ENTER: \n\n");
scanf("%d",&number);
switch (number) {
case 1:
printf("Enter the name of the bank: ");
scanf("%s",&name);
printf("%s\n\n",name);
case 2:
printf("Enter the name of the state in which this bank is located: ");
scanf("%s",&state);
printf("%s\n\n",state);
case 3:
printf("Enter the bank's net worth: ");
scanf("%d",&networth);
printf("%d\n\n",networth);
case 4:
printf("Enter the bank's rating: ");
scanf("%s",&rating);
printf("%s\n\n", rating);
default:
printf("Please choose one of the desired options' numbers only.");
}
}
return 0;
}
Please keep in mind that this is by no means a finished program. I had to stop coding because the warnings where too much to look at every time I compiled it.
Here is everything I get when I compile:
hw1.c: In function âmainâ:
hw1.c:14: warning: format â%dâ expects type âintâ, but argument 3 has type âchar *â
hw1.c:14: warning: format â%dâ expects type âintâ, but argument 4 has type âdoubleâ
hw1.c:15: warning: format â%dâ expects type âintâ, but argument 3 has type âdoubleâ
hw1.c:15: warning: format â%dâ expects type âintâ, but argument 4 has type âdoubleâ
hw1.c:25: warning: format â%sâ expects type âchar *â, but argument 2 has type âchar (*)[25]â
hw1.c:29: warning: format â%sâ expects type âchar *â, but argument 2 has type âchar (*)[25]â
hw1.c:33: warning: format â%dâ expects type âint *â, but argument 2 has type âdouble *â
hw1.c:34: warning: format â%dâ expects type âintâ, but argument 2 has type âdoubleâ
hw1.c:37: warning: format â%sâ expects type âchar *â, but argument 2 has type âchar (*)[25]â
Also, the reason for my while loop is that I need the code to continue asking for "number" after every case in my switch statement. That way, the user can keep changing the different variables as they wish. I need the program to only terminate if number is equal to 11.
There has got to be a more elegant way of going about this. I thought about putting "continue" at the end of each switch case so it resets, but I don't think that will work.
Any ideas?
Thank you all!
Soileau