【发布时间】:2023-03-24 04:35:01
【问题描述】:
我有一个小的 C 编程项目。我对这个主题真的很陌生,所以我感谢每一个小小的帮助。对象是:我需要用成对的数字填充一个数组,直到用户输入-1。然后用户在控制台中给出一个命令(更大或更小)。如果用户输入较小,则程序必须列出每一对,即第一个数字小于第二个数字。
我可以写到这个:
#include <stdio.h>
#define Max_Number 20
struct numberPairs {
int firstNum, secondNum;
};
struct numberPairs input(){
struct numberPairs firstInput;
printf("Please give me the first number! \n");
scanf("%d", &firstInput.firstNum);
printf("Please give me the second number! \n");
scanf("%d", &firstInput.secondNum);
return firstInput;
}
struct numberPairs ArrayInput (struct numberPairs x){
struct numberPairs array[Max_Number], pairs;
int index=0;
do{
pairs=input();
array[index]=pairs;
index++;
if (pairs.firstNum == -1 || pairs.secondNum == -1){
break;
}
}while(index<5 );
}
int main (){
struct numberPairs t;
ArrayInput(t);
}
基本上我不知道该怎么做。
【问题讨论】:
-
欢迎来到 Stack Overflow!请收下tour 并阅读How To Ask A Good Question 和How To Create A Minimal, Complete, And Verifiable Example。
-
您的问题到底是什么?它在哪里失败或你被困在哪里?