一个非常简单的问题.为什么在第一个while循环中跳过scanf.我已经尝试使用getchar(),结果是一样的.getchar被跳过了.
如果你们不明白我在说什么,你可以尝试编译它,你们会理解我在问什么.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct rec{
int num;
char pref[16];
float point;
struct rec* next;
}rec;
void dataInput(float*,char*);
rec* insertNode(rec*);
int main(){
int i=1;
rec* entr,*pt = NULL;
entr = (rec*) malloc(sizeof(rec));
entr->num = i;
dataInput(&entr->point,entr->pref);
entr->next = NULL;
char key;
i++;
while(1){
printf("Continue ? If YES press 'y',or NO press 'n'\n");
key = getchar();
if(key == 'n')break;
else if(key == 'y'){
if(!pt){
pt = insertNode(entr);
}else{
pt = insertNode(pt);
}
dataInput(&pt->point,pt->pref);
pt->num = i; …Run Code Online (Sandbox Code Playgroud) 我试图找出为什么我不能让它运行正常.我只想要用户输入四个,并在最后运行计算.
#include <stdio.h>
#include <math.h>
int main(){
double amount; /* amount on deposit */
double principal; /* what's the principal */
double rate; /* annual interest rate */
int year; /* year placeholder and no. of total years */
int yearNo;
printf("What is the principal? ");
scanf("%d", &principal);
printf("What is the rate (in decimal)? ");
scanf(" .2%d", &rate);
printf("What is the principal? ");
scanf(" %d", &principal);
printf("How many years? ");
scanf(" %d\n", yearNo);
printf("%4s%21s\n", "Year", "Amount on deposit");
/* calculate …Run Code Online (Sandbox Code Playgroud)